1+ import 'package:flet_view/utils/user_fonts.dart' ;
12import 'package:flutter/material.dart' ;
23import 'package:flutter_redux/flutter_redux.dart' ;
34
@@ -11,6 +12,7 @@ import '../utils/colors.dart';
1112import '../utils/desktop.dart' ;
1213import '../utils/edge_insets.dart' ;
1314import '../utils/theme.dart' ;
15+ import '../utils/uri.dart' ;
1416import '../widgets/page_media.dart' ;
1517import 'app_bar.dart' ;
1618import 'create_control.dart' ;
@@ -110,89 +112,109 @@ class PageControl extends StatelessWidget {
110112 childIds.add (appBar.id);
111113 }
112114
113- return StoreConnector <AppState , PageMediaViewModel >(
115+ return StoreConnector <AppState , Uri ? >(
114116 distinct: true ,
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 >(
117+ converter: (store) => store.state.pageUri,
118+ builder: (context, pageUri) {
119+ // load custom fonts
120+ parseFonts (control, "fonts" ).forEach ((fontFamily, fontUrl) {
121+ var fontUri = Uri .parse (fontUrl);
122+ if (! fontUri.hasAuthority) {
123+ fontUri = getAssetUri (pageUri! , fontUrl);
124+ }
125+ debugPrint ("fontUri: $fontUri " );
126+ UserFonts .loadFont (fontFamily, fontUri);
127+ });
128+
129+ return StoreConnector <AppState , PageMediaViewModel >(
124130 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- );
131+ converter: (store) => PageMediaViewModel .fromStore (store),
132+ builder: (context, media) {
133+ var theme = themeMode == ThemeMode .light ||
134+ (themeMode == ThemeMode .system &&
135+ media.displayBrightness == Brightness .light)
136+ ? lightTheme
137+ : darkTheme;
138+
139+ return StoreConnector <AppState , ControlsViewModel >(
140+ distinct: true ,
141+ converter: (store) =>
142+ ControlsViewModel .fromStore (store, childIds),
143+ builder: (context, childrenViews) {
144+ debugPrint ("Offstage StoreConnector build" );
145+
146+ // offstage
147+ List <Widget > offstageWidgets = offstage != null
148+ ? childrenViews.controlViews.first.children
149+ .where ((c) =>
150+ c.isVisible &&
151+ c.type != ControlType .floatingActionButton)
152+ .map ((c) =>
153+ createControl (offstage, c.id, disabled))
154+ .toList ()
155+ : [];
156+
157+ List <Control > fab = offstage != null
158+ ? childrenViews.controlViews.first.children
159+ .where ((c) =>
160+ c.isVisible &&
161+ c.type == ControlType .floatingActionButton)
162+ .toList ()
163+ : [];
164+
165+ var appBarView = appBar != null
166+ ? childrenViews.controlViews.last
167+ : null ;
168+
169+ var column = Column (
170+ mainAxisAlignment: mainAlignment,
171+ crossAxisAlignment: crossAlignment,
172+ children: controls);
173+
174+ return MaterialApp (
175+ title: title,
176+ theme: lightTheme,
177+ darkTheme: darkTheme,
178+ themeMode: themeMode,
179+ home: Scaffold (
180+ appBar: appBarView != null
181+ ? AppBarControl (
182+ parent: control,
183+ control: appBarView.control,
184+ children: appBarView.children,
185+ parentDisabled: disabled,
186+ height: appBarView.control.attrDouble (
187+ "toolbarHeight" , kToolbarHeight)! ,
188+ theme: theme)
189+ : null ,
190+ body: Stack (children: [
191+ SizedBox .expand (
192+ child: Container (
193+ padding:
194+ parseEdgeInsets (control, "padding" ) ??
195+ const EdgeInsets .all (10 ),
196+ decoration: BoxDecoration (
197+ color: HexColor .fromString (
198+ theme,
199+ control.attrString (
200+ "bgcolor" , "" )! )),
201+ child: scrollMode != ScrollMode .none
202+ ? ScrollableControl (
203+ child: column,
204+ scrollDirection: Axis .vertical,
205+ scrollMode: scrollMode,
206+ autoScroll: autoScroll,
207+ )
208+ : column)),
209+ ...offstageWidgets,
210+ const PageMedia ()
211+ ]),
212+ floatingActionButton: fab.isNotEmpty
213+ ? createControl (offstage, fab.first.id, disabled)
214+ : null ,
215+ ),
216+ );
217+ });
196218 });
197219 });
198220 }
0 commit comments