diff --git a/lib/demo_buttons.dart b/lib/demo_buttons.dart new file mode 100644 index 0000000..b54782a --- /dev/null +++ b/lib/demo_buttons.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; + +class DemoButtons extends StatefulWidget { + const DemoButtons({super.key}); + + @override + State createState() { + return _DemoButtonsState(); + } +} + +class _DemoButtonsState extends State { + var _isUnderstood = false; + + @override + Widget build(BuildContext context) { + print('DemoButtons BUILD called'); + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + TextButton( + onPressed: () { + setState(() { + _isUnderstood = false; + }); + }, + child: const Text('No'), + ), + TextButton( + onPressed: () { + setState(() { + _isUnderstood = true; + }); + }, + child: const Text('Yes'), + ), + ], + ), + if (_isUnderstood) const Text('Awesome!'), + ], + ); + } +} diff --git a/lib/ui_updates_demo.dart b/lib/ui_updates_demo.dart index d1483f4..da9d28d 100644 --- a/lib/ui_updates_demo.dart +++ b/lib/ui_updates_demo.dart @@ -1,23 +1,9 @@ import 'package:flutter/material.dart'; +import 'package:flutter_internals/demo_buttons.dart'; -class UIUpdatesDemo extends StatefulWidget { +class UIUpdatesDemo extends StatelessWidget { const UIUpdatesDemo({super.key}); - @override - StatefulElement createElement() { - print('UIUpdatesDemo CREATEELEMENT called'); - return super.createElement(); - } - - @override - State createState() { - return _UIUpdatesDemo(); - } -} - -class _UIUpdatesDemo extends State { - var _isUnderstood = false; - @override Widget build(BuildContext context) { print('UIUpdatesDemo BUILD called'); @@ -27,40 +13,19 @@ class _UIUpdatesDemo extends State { child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const Text( + children: const [ + Text( 'Every Flutter developer should have a basic understanding of Flutter\'s internals!', textAlign: TextAlign.center, style: TextStyle(fontWeight: FontWeight.bold), ), - const SizedBox(height: 16), - const Text( + SizedBox(height: 16), + Text( 'Do you understand how Flutter updates UIs?', textAlign: TextAlign.center, ), - const SizedBox(height: 24), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - onPressed: () { - setState(() { - _isUnderstood = false; - }); - }, - child: const Text('No'), - ), - TextButton( - onPressed: () { - setState(() { - _isUnderstood = true; - }); - }, - child: const Text('Yes'), - ), - ], - ), - if (_isUnderstood) const Text('Awesome!'), + SizedBox(height: 24), + Expanded(child: DemoButtons(),), ], ), ),