Dark mode

This commit is contained in:
unknown 2018-07-31 16:10:44 +03:00
parent d740d5d7c5
commit 1d282a1bef
4 changed files with 14 additions and 13 deletions

View File

@ -32,8 +32,11 @@ import 'package:invoiceninja_flutter/ui/invoice/invoice_screen.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
void main() async {
final prefs = await SharedPreferences.getInstance();
final enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode);
final store = Store<AppState>(appReducer,
initialState: AppState(),
initialState: AppState(enableDarkMode: enableDarkMode),
middleware: []
..addAll(createStoreAuthMiddleware())
..addAll(createStoreDashboardMiddleware())
@ -45,16 +48,12 @@ void main() async {
LoggingMiddleware<dynamic>.printer(),
]));
final prefs = await SharedPreferences.getInstance();
final enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode);
runApp(InvoiceNinjaApp(store: store, enableDarkMode: enableDarkMode));
runApp(InvoiceNinjaApp(store: store));
}
class InvoiceNinjaApp extends StatefulWidget {
final Store<AppState> store;
final bool enableDarkMode;
const InvoiceNinjaApp({Key key, this.store, this.enableDarkMode})
const InvoiceNinjaApp({Key key, this.store})
: super(key: key);
@override
@ -75,7 +74,7 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
],
// light theme
theme: widget.enableDarkMode
theme: widget.store.state.uiState.enableDarkMode
? ThemeData(
brightness: Brightness.dark,
accentColor: Colors.lightBlueAccent,

View File

@ -9,7 +9,9 @@ import 'package:invoiceninja_flutter/redux/company/company_reducer.dart';
// We create the State reducer by combining many smaller reducers into one!
AppState appReducer(AppState state, dynamic action) {
if (action is UserLogout) {
return AppState().rebuild((b) => b.authState.replace(state.authState));
return AppState().rebuild((b) => b
..authState.replace(state.authState)
..uiState.enableDarkMode = state.uiState.enableDarkMode);
} else if (action is LoadStateSuccess) {
return action.state.rebuild((b) => b
..isLoading = false

View File

@ -16,7 +16,7 @@ part 'app_state.g.dart';
abstract class AppState implements Built<AppState, AppStateBuilder> {
factory AppState() {
factory AppState({bool enableDarkMode}) {
return _$AppState._(
isLoading: false,
isSaving: false,
@ -27,7 +27,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
companyState3: CompanyState(),
companyState4: CompanyState(),
companyState5: CompanyState(),
uiState: UIState(),
uiState: UIState(enableDarkMode: enableDarkMode),
);
}
AppState._();

View File

@ -9,11 +9,11 @@ part 'ui_state.g.dart';
abstract class UIState implements Built<UIState, UIStateBuilder> {
factory UIState() {
factory UIState({bool enableDarkMode}) {
return _$UIState._(
selectedCompanyIndex: 0,
currentRoute: LoginScreen.route,
enableDarkMode: false,
enableDarkMode: enableDarkMode ?? false,
productUIState: ProductUIState(),
clientUIState: ClientUIState(),
invoiceUIState: InvoiceUIState(),