@@ -13,9 +13,7 @@ class MyApp extends StatelessWidget {
1313 @override
1414 Widget build (BuildContext context) {
1515 return MaterialApp (
16- theme: ThemeData (
17- primaryColor: const Color (0xff6200ee ),
18- ),
16+ theme: ThemeData (primaryColor: const Color (0xff6200ee )),
1917 home: const BookDetail (),
2018 );
2119 }
@@ -70,30 +68,33 @@ class _BookDetailState extends State<BookDetail> {
7068 // calls from the platform.
7169 // TODO(gaaclarke): make the setup method an instance method so it's
7270 // injectable https://github.com/flutter/flutter/issues/59119.
73- FlutterBookApi .setup (FlutterBookApiHandler (
71+ FlutterBookApi .setup (
72+ FlutterBookApiHandler (
7473 // The `FlutterBookApi` just has one method. Just give a closure for that
7574 // method to the handler class.
7675 (book) {
77- setState (() {
78- // This book model is what we're going to return to Kotlin eventually.
79- // Keep it bound to the UI.
80- this .book = book;
81- titleTextController.text = book.title ?? '' ;
82- titleTextController.addListener (() {
83- this .book! .title = titleTextController.text;
84- });
85- // Subtitle could be null.
86- // TODO(gaaclarke): https://github.com/flutter/flutter/issues/59118.
87- subtitleTextController.text = book.subtitle ?? '' ;
88- subtitleTextController.addListener (() {
89- this .book! .subtitle = subtitleTextController.text;
90- });
91- authorTextController.text = book.author ?? '' ;
92- authorTextController.addListener (() {
93- this .book! .author = authorTextController.text;
94- });
95- });
96- }));
76+ setState (() {
77+ // This book model is what we're going to return to Kotlin eventually.
78+ // Keep it bound to the UI.
79+ this .book = book;
80+ titleTextController.text = book.title ?? '' ;
81+ titleTextController.addListener (() {
82+ this .book! .title = titleTextController.text;
83+ });
84+ // Subtitle could be null.
85+ // TODO(gaaclarke): https://github.com/flutter/flutter/issues/59118.
86+ subtitleTextController.text = book.subtitle ?? '' ;
87+ subtitleTextController.addListener (() {
88+ this .book! .subtitle = subtitleTextController.text;
89+ });
90+ authorTextController.text = book.author ?? '' ;
91+ authorTextController.addListener (() {
92+ this .book! .author = authorTextController.text;
93+ });
94+ });
95+ },
96+ ),
97+ );
9798 }
9899
99100 // Not overriding didUpdateWidget because the Android program can't change
@@ -124,26 +125,28 @@ class _BookDetailState extends State<BookDetail> {
124125 IconButton (
125126 icon: const Icon (Icons .check),
126127 // Pressing save sends the updated book to the platform.
127- onPressed: book != null
128- ? () {
129- hostApi.finishEditingBook (book! );
130- clear ();
131- }
132- : null ,
128+ onPressed:
129+ book != null
130+ ? () {
131+ hostApi.finishEditingBook (book! );
132+ clear ();
133+ }
134+ : null ,
133135 ),
134136 ],
135137 ),
136- body: book == null
137- // Draw a spinner until the platform gives us the book to show details
138- // for.
139- ? const Center (child: CircularProgressIndicator ())
140- : BookForm (
141- book: book! ,
142- focusNode: textFocusNode,
143- authorTextController: authorTextController,
144- subtitleTextController: subtitleTextController,
145- titleTextController: titleTextController,
146- ),
138+ body:
139+ book == null
140+ // Draw a spinner until the platform gives us the book to show details
141+ // for.
142+ ? const Center (child: CircularProgressIndicator ())
143+ : BookForm (
144+ book: book! ,
145+ focusNode: textFocusNode,
146+ authorTextController: authorTextController,
147+ subtitleTextController: subtitleTextController,
148+ titleTextController: titleTextController,
149+ ),
147150 );
148151 }
149152}
@@ -207,15 +210,14 @@ class BookForm extends StatelessWidget {
207210 child: Padding (
208211 padding: const EdgeInsets .all (8.0 ),
209212 child: Text (
210- '${book .pageCount } pages ~ published ${book .publishDate }' ),
213+ '${book .pageCount } pages ~ published ${book .publishDate }' ,
214+ ),
211215 ),
212216 ),
213217 const Divider (),
214218 const SizedBox (height: 32 ),
215219 if (book.thumbnail? .url != null ) ...[
216- Center (
217- child: Image .network (book.thumbnail! .url! ),
218- ),
220+ Center (child: Image .network (book.thumbnail! .url! )),
219221 const SizedBox (height: 32 ),
220222 ],
221223 if (book.summary != null ) ...[
@@ -234,7 +236,7 @@ class BookForm extends StatelessWidget {
234236 book.summary ?? '' ,
235237 style: TextStyle (color: Colors .grey.shade600, height: 1.24 ),
236238 ),
237- ]
239+ ],
238240 ],
239241 ),
240242 );
0 commit comments