Skip to content

Commit 1ad1a11

Browse files
Fixed #10 (#14)
1 parent b841a6e commit 1ad1a11

File tree

10 files changed

+435
-122
lines changed

10 files changed

+435
-122
lines changed

client/lib/actions.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class PageSizeChangeAction {
2727
PageSizeChangeAction(this.newSize);
2828
}
2929

30+
class PageBrightnessChangeAction {
31+
final Brightness brightness;
32+
PageBrightnessChangeAction(this.brightness);
33+
}
34+
3035
class RegisterWebClientAction {
3136
final RegisterWebClientResponse payload;
3237
RegisterWebClientAction(this.payload);

client/lib/controls/app_bar.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ class AppBarControl extends StatelessWidget implements PreferredSizeWidget {
1010
final bool parentDisabled;
1111
final List<Control> children;
1212
final double height;
13+
final ThemeData theme;
1314

1415
const AppBarControl(
1516
{Key? key,
1617
this.parent,
1718
required this.control,
1819
required this.children,
1920
required this.parentDisabled,
20-
required this.height})
21+
required this.height,
22+
required this.theme})
2123
: super(key: key);
2224

2325
@override
@@ -31,10 +33,9 @@ class AppBarControl extends StatelessWidget implements PreferredSizeWidget {
3133

3234
var leadingWidth = control.attrDouble("leadingWidth");
3335
var centerTitle = control.attrBool("centerTitle", false)!;
34-
var color = HexColor.fromString(
35-
Theme.of(context), control.attrString("color", "")!);
36-
var bgcolor = HexColor.fromString(
37-
Theme.of(context), control.attrString("bgcolor", "")!);
36+
var color = HexColor.fromString(theme, control.attrString("color", "")!);
37+
var bgcolor =
38+
HexColor.fromString(theme, control.attrString("bgcolor", "")!);
3839

3940
return AppBar(
4041
leading: leadingCtrls.isNotEmpty

client/lib/controls/page.dart

Lines changed: 86 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import '../models/app_state.dart';
55
import '../models/control.dart';
66
import '../models/control_type.dart';
77
import '../models/controls_view_model.dart';
8+
import '../models/page_media_view_model.dart';
89
import '../utils/alignment.dart';
910
import '../utils/colors.dart';
1011
import '../utils/desktop.dart';
1112
import '../utils/edge_insets.dart';
1213
import '../utils/theme.dart';
13-
import '../widgets/screen_size.dart';
14+
import '../widgets/page_media.dart';
1415
import 'app_bar.dart';
1516
import 'create_control.dart';
1617
import '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
}

client/lib/models/app_state.dart

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AppState extends Equatable {
1717
final String error;
1818
final Size size;
1919
final String sizeBreakpoint;
20+
final Brightness displayBrightness;
2021
final Map<String, double> sizeBreakpoints;
2122
final Map<String, Control> controls;
2223

@@ -29,25 +30,27 @@ class AppState extends Equatable {
2930
required this.size,
3031
required this.sizeBreakpoint,
3132
required this.sizeBreakpoints,
33+
required this.displayBrightness,
3234
required this.controls});
3335

3436
factory AppState.initial() => const AppState(
35-
pageUri: null,
36-
sessionId: "",
37-
isLoading: true,
38-
reconnectingTimeout: 0,
39-
error: "",
40-
size: Size(0, 0),
41-
sizeBreakpoint: "",
42-
sizeBreakpoints: {
43-
"xs": 0,
44-
"sm": 576,
45-
"md": 768,
46-
"lg": 992,
47-
"xl": 1200,
48-
"xxl": 1400
49-
},
50-
controls: {});
37+
pageUri: null,
38+
sessionId: "",
39+
isLoading: true,
40+
reconnectingTimeout: 0,
41+
error: "",
42+
size: Size(0, 0),
43+
sizeBreakpoint: "",
44+
sizeBreakpoints: {
45+
"xs": 0,
46+
"sm": 576,
47+
"md": 768,
48+
"lg": 992,
49+
"xl": 1200,
50+
"xxl": 1400
51+
},
52+
displayBrightness: Brightness.light,
53+
controls: {});
5154

5255
AppState copyWith(
5356
{Uri? pageUri,
@@ -58,6 +61,7 @@ class AppState extends Equatable {
5861
Size? size,
5962
String? sizeBreakpoint,
6063
Map<String, double>? sizeBreakpoints,
64+
Brightness? displayBrightness,
6165
Map<String, Control>? controls}) =>
6266
AppState(
6367
pageUri: pageUri ?? this.pageUri,
@@ -68,6 +72,7 @@ class AppState extends Equatable {
6872
size: size ?? this.size,
6973
sizeBreakpoint: sizeBreakpoint ?? this.sizeBreakpoint,
7074
sizeBreakpoints: sizeBreakpoints ?? this.sizeBreakpoints,
75+
displayBrightness: displayBrightness ?? this.displayBrightness,
7176
controls: controls ?? this.controls);
7277

7378
@override

client/lib/models/page_load_view_model.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import 'package:equatable/equatable.dart';
22
import 'package:redux/redux.dart';
33

44
import 'app_state.dart';
5-
import 'page_size_view_model.dart';
5+
import 'page_media_view_model.dart';
66

77
class PageLoadViewModel extends Equatable {
88
final Uri? pageUri;
99
final String sessionId;
10-
final PageSizeViewModel sizeViewModel;
10+
final PageMediaViewModel sizeViewModel;
1111

1212
const PageLoadViewModel(
1313
{required this.pageUri,
@@ -18,7 +18,7 @@ class PageLoadViewModel extends Equatable {
1818
return PageLoadViewModel(
1919
pageUri: store.state.pageUri,
2020
sessionId: store.state.sessionId,
21-
sizeViewModel: PageSizeViewModel.fromStore(store));
21+
sizeViewModel: PageMediaViewModel.fromStore(store));
2222
}
2323

2424
@override
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'dart:ui';
2+
3+
import 'package:equatable/equatable.dart';
4+
import 'package:redux/redux.dart';
5+
6+
import 'app_state.dart';
7+
8+
class PageMediaViewModel extends Equatable {
9+
final Size size;
10+
final Brightness displayBrightness;
11+
final Function dispatch;
12+
13+
const PageMediaViewModel(
14+
{required this.size,
15+
required this.displayBrightness,
16+
required this.dispatch});
17+
18+
static PageMediaViewModel fromStore(Store<AppState> store) {
19+
return PageMediaViewModel(
20+
size: store.state.size,
21+
displayBrightness: store.state.displayBrightness,
22+
dispatch: store.dispatch);
23+
}
24+
25+
@override
26+
List<Object?> get props => [size, displayBrightness, dispatch];
27+
}

client/lib/models/page_size_view_model.dart

Lines changed: 0 additions & 20 deletions
This file was deleted.

client/lib/reducers.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ AppState appReducer(AppState state, dynamic action) {
5858
}
5959

6060
return state.copyWith(size: action.newSize, sizeBreakpoint: newBreakpoint);
61+
} else if (action is PageBrightnessChangeAction) {
62+
return state.copyWith(displayBrightness: action.brightness);
6163
} else if (action is RegisterWebClientAction) {
6264
//
6365
// register web client

0 commit comments

Comments
 (0)