This commit is contained in:
2024-03-05 08:14:04 +01:00
parent 7533b8f662
commit cc427dc467
2 changed files with 54 additions and 43 deletions
+46
View File
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
class DemoButtons extends StatefulWidget {
const DemoButtons({super.key});
@override
State<StatefulWidget> createState() {
return _DemoButtonsState();
}
}
class _DemoButtonsState extends State<DemoButtons> {
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!'),
],
);
}
}
+8 -43
View File
@@ -1,23 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_internals/demo_buttons.dart';
class UIUpdatesDemo extends StatefulWidget { class UIUpdatesDemo extends StatelessWidget {
const UIUpdatesDemo({super.key}); const UIUpdatesDemo({super.key});
@override
StatefulElement createElement() {
print('UIUpdatesDemo CREATEELEMENT called');
return super.createElement();
}
@override
State<UIUpdatesDemo> createState() {
return _UIUpdatesDemo();
}
}
class _UIUpdatesDemo extends State<UIUpdatesDemo> {
var _isUnderstood = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print('UIUpdatesDemo BUILD called'); print('UIUpdatesDemo BUILD called');
@@ -27,40 +13,19 @@ class _UIUpdatesDemo extends State<UIUpdatesDemo> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: const [
const Text( Text(
'Every Flutter developer should have a basic understanding of Flutter\'s internals!', 'Every Flutter developer should have a basic understanding of Flutter\'s internals!',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(fontWeight: FontWeight.bold),
), ),
const SizedBox(height: 16), SizedBox(height: 16),
const Text( Text(
'Do you understand how Flutter updates UIs?', 'Do you understand how Flutter updates UIs?',
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
const SizedBox(height: 24), SizedBox(height: 24),
Row( Expanded(child: DemoButtons(),),
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!'),
], ],
), ),
), ),