@@ -5,12 +5,13 @@ import '../models/app_state.dart';
55import '../models/control.dart' ;
66import '../models/control_type.dart' ;
77import '../models/controls_view_model.dart' ;
8+ import '../models/page_media_view_model.dart' ;
89import '../utils/alignment.dart' ;
910import '../utils/colors.dart' ;
1011import '../utils/desktop.dart' ;
1112import '../utils/edge_insets.dart' ;
1213import '../utils/theme.dart' ;
13- import '../widgets/screen_size .dart' ;
14+ import '../widgets/page_media .dart' ;
1415import 'app_bar.dart' ;
1516import 'create_control.dart' ;
1617import 'scrollable_control.dart' ;
@@ -73,7 +74,7 @@ class PageControl extends StatelessWidget {
7374 }
7475
7576 // theme
76- var theme = parseTheme (control, "theme" ) ??
77+ var lightTheme = parseTheme (control, "theme" ) ??
7778 ThemeData (
7879 colorSchemeSeed: Colors .blue,
7980 brightness: Brightness .light,
@@ -109,76 +110,90 @@ class PageControl extends StatelessWidget {
109110 childIds.add (appBar.id);
110111 }
111112
112- return StoreConnector <AppState , ControlsViewModel >(
113+ return StoreConnector <AppState , PageMediaViewModel >(
113114 distinct: true ,
114- converter: (store) => ControlsViewModel .fromStore (store, childIds),
115- builder: (context, childrenViews) {
116- debugPrint ("Offstage StoreConnector build" );
117-
118- // offstage
119- List <Widget > offstageWidgets = offstage != null
120- ? childrenViews.controlViews.first.children
121- .where ((c) =>
122- c.isVisible && c.type != ControlType .floatingActionButton)
123- .map ((c) => createControl (offstage, c.id, disabled))
124- .toList ()
125- : [];
126-
127- List <Control > fab = offstage != null
128- ? childrenViews.controlViews.first.children
129- .where ((c) =>
130- c.isVisible && c.type == ControlType .floatingActionButton)
131- .toList ()
132- : [];
133-
134- var appBarView =
135- appBar != null ? childrenViews.controlViews.last : null ;
136-
137- var column = Column (
138- mainAxisAlignment: mainAlignment,
139- crossAxisAlignment: crossAlignment,
140- children: controls);
141-
142- return MaterialApp (
143- title: title,
144- theme: theme,
145- darkTheme: darkTheme,
146- themeMode: themeMode,
147- home: Scaffold (
148- appBar: appBarView != null
149- ? AppBarControl (
150- parent: control,
151- control: appBarView.control,
152- children: appBarView.children,
153- parentDisabled: disabled,
154- height: appBarView.control
155- .attrDouble ("toolbarHeight" , kToolbarHeight)! ,
156- )
157- : null ,
158- body: Stack (children: [
159- SizedBox .expand (
160- child: Container (
161- padding: parseEdgeInsets (control, "padding" ) ??
162- const EdgeInsets .all (10 ),
163- decoration: BoxDecoration (
164- color: HexColor .fromString (Theme .of (context),
165- control.attrString ("bgcolor" , "" )! )),
166- child: scrollMode != ScrollMode .none
167- ? ScrollableControl (
168- child: column,
169- scrollDirection: Axis .vertical,
170- scrollMode: scrollMode,
171- autoScroll: autoScroll,
172- )
173- : column)),
174- ...offstageWidgets,
175- const ScreenSize ()
176- ]),
177- floatingActionButton: fab.isNotEmpty
178- ? createControl (offstage, fab.first.id, disabled)
179- : null ,
180- ),
181- );
115+ converter: (store) => PageMediaViewModel .fromStore (store),
116+ builder: (context, media) {
117+ var theme = themeMode == ThemeMode .light ||
118+ (themeMode == ThemeMode .system &&
119+ media.displayBrightness == Brightness .light)
120+ ? lightTheme
121+ : darkTheme;
122+
123+ return StoreConnector <AppState , ControlsViewModel >(
124+ distinct: true ,
125+ converter: (store) =>
126+ ControlsViewModel .fromStore (store, childIds),
127+ builder: (context, childrenViews) {
128+ debugPrint ("Offstage StoreConnector build" );
129+
130+ // offstage
131+ List <Widget > offstageWidgets = offstage != null
132+ ? childrenViews.controlViews.first.children
133+ .where ((c) =>
134+ c.isVisible &&
135+ c.type != ControlType .floatingActionButton)
136+ .map ((c) => createControl (offstage, c.id, disabled))
137+ .toList ()
138+ : [];
139+
140+ List <Control > fab = offstage != null
141+ ? childrenViews.controlViews.first.children
142+ .where ((c) =>
143+ c.isVisible &&
144+ c.type == ControlType .floatingActionButton)
145+ .toList ()
146+ : [];
147+
148+ var appBarView =
149+ appBar != null ? childrenViews.controlViews.last : null ;
150+
151+ var column = Column (
152+ mainAxisAlignment: mainAlignment,
153+ crossAxisAlignment: crossAlignment,
154+ children: controls);
155+
156+ return MaterialApp (
157+ title: title,
158+ theme: lightTheme,
159+ darkTheme: darkTheme,
160+ themeMode: themeMode,
161+ home: Scaffold (
162+ appBar: appBarView != null
163+ ? AppBarControl (
164+ parent: control,
165+ control: appBarView.control,
166+ children: appBarView.children,
167+ parentDisabled: disabled,
168+ height: appBarView.control
169+ .attrDouble ("toolbarHeight" , kToolbarHeight)! ,
170+ theme: theme)
171+ : null ,
172+ body: Stack (children: [
173+ SizedBox .expand (
174+ child: Container (
175+ padding: parseEdgeInsets (control, "padding" ) ??
176+ const EdgeInsets .all (10 ),
177+ decoration: BoxDecoration (
178+ color: HexColor .fromString (theme,
179+ control.attrString ("bgcolor" , "" )! )),
180+ child: scrollMode != ScrollMode .none
181+ ? ScrollableControl (
182+ child: column,
183+ scrollDirection: Axis .vertical,
184+ scrollMode: scrollMode,
185+ autoScroll: autoScroll,
186+ )
187+ : column)),
188+ ...offstageWidgets,
189+ const PageMedia ()
190+ ]),
191+ floatingActionButton: fab.isNotEmpty
192+ ? createControl (offstage, fab.first.id, disabled)
193+ : null ,
194+ ),
195+ );
196+ });
182197 });
183198 }
184199}
0 commit comments