@@ -15,36 +15,63 @@ class MyApp extends StatelessWidget {
1515 theme: ThemeData (
1616 primarySwatch: Colors .blue,
1717 ),
18- home: const HomePage (title: '015 Row & Column' ),
18+ home: HomePage (title: '015 Row & Column' ),
1919 );
2020 }
2121}
2222
2323class HomePage extends StatelessWidget {
24- const HomePage ({Key ? key, required this .title}) : super (key: key);
24+ HomePage ({Key ? key, required this .title}) : super (key: key);
2525 final String title;
2626
27+ final ValueNotifier <bool > enable = ValueNotifier (false );
28+
2729 @override
2830 Widget build (BuildContext context) {
2931 return Scaffold (
3032 appBar: AppBar (
3133 title: Text (title),
34+ bottom: PreferredSize (
35+ preferredSize: const Size (0.0 , 160.0 ),
36+ child: Column (
37+ children: [
38+ _buildDropDown (MainAxisSize .values, onChanged: (value) {
39+ FlexNotifier .instance ().mainAxisSize = value! ;
40+ }, initValue: FlexNotifier .instance ().mainAxisSize),
41+ _buildDropDown (MainAxisAlignment .values, onChanged: (value) {
42+ FlexNotifier .instance ().mainAxisAlignment = value! ;
43+ }, initValue: FlexNotifier .instance ().mainAxisAlignment),
44+ _buildDropDown (CrossAxisAlignment .values, onChanged: (value) {
45+ FlexNotifier .instance ().crossAxisAlignment = value! ;
46+ }, initValue: FlexNotifier .instance ().crossAxisAlignment),
47+ StatefulBuilder (
48+ builder: (context, setState) {
49+ return Row (
50+ mainAxisSize: MainAxisSize .max,
51+ mainAxisAlignment: MainAxisAlignment .center,
52+ children: [
53+ const Text ("Column" ),
54+ Switch (
55+ value: enable.value,
56+ onChanged: (value) {
57+ setState (() {
58+ enable.value = value;
59+ });
60+ }),
61+ const Text ("Row" ),
62+ ],
63+ );
64+ }
65+ )
66+ ],
67+ ),
68+ ),
3269 ),
33- body: Column (
34- children: < Widget > [
35- _buildDropDown (MainAxisSize .values, onChanged: (value) {
36- FlexNotifier .instance ().mainAxisSize = value! ;
37- }, initValue: FlexNotifier .instance ().mainAxisSize),
38- _buildDropDown (MainAxisAlignment .values, onChanged: (value) {
39- FlexNotifier .instance ().mainAxisAlignment = value! ;
40- }, initValue: FlexNotifier .instance ().mainAxisAlignment),
41- _buildDropDown (CrossAxisAlignment .values, onChanged: (value) {
42- FlexNotifier .instance ().crossAxisAlignment = value! ;
43- }, initValue: FlexNotifier .instance ().crossAxisAlignment),
44- const SizedBox (height: 100 ,),
45- Container (decoration: const BoxDecoration (color: Colors .amber), child: const RowWidget ()),
46- ],
47- ),
70+ body: ValueListenableBuilder (
71+ valueListenable: enable,
72+ builder: (context, bool value, Widget ? child) {
73+ return Container (decoration: const BoxDecoration (color: Colors .amber), child: value ? const RowWidget () : const ColumnWidget ());
74+ }),
4875 );
4976 }
5077
@@ -107,6 +134,45 @@ class _RowWidgetState extends State<RowWidget> {
107134 }
108135}
109136
137+ class ColumnWidget extends StatefulWidget {
138+ const ColumnWidget ({super .key});
139+
140+ @override
141+ State <ColumnWidget > createState () => _ColumnWidgetState ();
142+ }
143+
144+ class _ColumnWidgetState extends State <ColumnWidget > {
145+ @override
146+ void initState () {
147+ super .initState ();
148+ FlexNotifier .instance ().addListener (_refresh);
149+ }
150+
151+ @override
152+ void dispose () {
153+ FlexNotifier .instance ().removeListener (_refresh);
154+ super .dispose ();
155+ }
156+
157+ @override
158+ Widget build (BuildContext context) {
159+ return Column (
160+ mainAxisSize: FlexNotifier .instance ().mainAxisSize,
161+ mainAxisAlignment: FlexNotifier .instance ().mainAxisAlignment,
162+ crossAxisAlignment: FlexNotifier .instance ().crossAxisAlignment,
163+ children: const [
164+ Icon (Icons .card_giftcard, size: 32.0 ),
165+ Icon (Icons .card_giftcard, size: 80.0 ),
166+ Icon (Icons .card_giftcard, size: 48.0 ),
167+ ],
168+ );
169+ }
170+
171+ _refresh () {
172+ setState (() {});
173+ }
174+ }
175+
110176class FlexNotifier with ChangeNotifier {
111177 FlexNotifier ._();
112178
0 commit comments