Dark mode
This commit is contained in:
parent
d740d5d7c5
commit
1d282a1bef
|
|
@ -32,8 +32,11 @@ import 'package:invoiceninja_flutter/ui/invoice/invoice_screen.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode);
|
||||||
|
|
||||||
final store = Store<AppState>(appReducer,
|
final store = Store<AppState>(appReducer,
|
||||||
initialState: AppState(),
|
initialState: AppState(enableDarkMode: enableDarkMode),
|
||||||
middleware: []
|
middleware: []
|
||||||
..addAll(createStoreAuthMiddleware())
|
..addAll(createStoreAuthMiddleware())
|
||||||
..addAll(createStoreDashboardMiddleware())
|
..addAll(createStoreDashboardMiddleware())
|
||||||
|
|
@ -45,16 +48,12 @@ void main() async {
|
||||||
LoggingMiddleware<dynamic>.printer(),
|
LoggingMiddleware<dynamic>.printer(),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
runApp(InvoiceNinjaApp(store: store));
|
||||||
final enableDarkMode = prefs.getBool(kSharedPrefEnableDarkMode);
|
|
||||||
|
|
||||||
runApp(InvoiceNinjaApp(store: store, enableDarkMode: enableDarkMode));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvoiceNinjaApp extends StatefulWidget {
|
class InvoiceNinjaApp extends StatefulWidget {
|
||||||
final Store<AppState> store;
|
final Store<AppState> store;
|
||||||
final bool enableDarkMode;
|
const InvoiceNinjaApp({Key key, this.store})
|
||||||
const InvoiceNinjaApp({Key key, this.store, this.enableDarkMode})
|
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -75,7 +74,7 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
|
||||||
],
|
],
|
||||||
|
|
||||||
// light theme
|
// light theme
|
||||||
theme: widget.enableDarkMode
|
theme: widget.store.state.uiState.enableDarkMode
|
||||||
? ThemeData(
|
? ThemeData(
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
accentColor: Colors.lightBlueAccent,
|
accentColor: Colors.lightBlueAccent,
|
||||||
|
|
|
||||||
|
|
@ -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!
|
// We create the State reducer by combining many smaller reducers into one!
|
||||||
AppState appReducer(AppState state, dynamic action) {
|
AppState appReducer(AppState state, dynamic action) {
|
||||||
if (action is UserLogout) {
|
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) {
|
} else if (action is LoadStateSuccess) {
|
||||||
return action.state.rebuild((b) => b
|
return action.state.rebuild((b) => b
|
||||||
..isLoading = false
|
..isLoading = false
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ part 'app_state.g.dart';
|
||||||
|
|
||||||
abstract class AppState implements Built<AppState, AppStateBuilder> {
|
abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
|
|
||||||
factory AppState() {
|
factory AppState({bool enableDarkMode}) {
|
||||||
return _$AppState._(
|
return _$AppState._(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isSaving: false,
|
isSaving: false,
|
||||||
|
|
@ -27,7 +27,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
companyState3: CompanyState(),
|
companyState3: CompanyState(),
|
||||||
companyState4: CompanyState(),
|
companyState4: CompanyState(),
|
||||||
companyState5: CompanyState(),
|
companyState5: CompanyState(),
|
||||||
uiState: UIState(),
|
uiState: UIState(enableDarkMode: enableDarkMode),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AppState._();
|
AppState._();
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ part 'ui_state.g.dart';
|
||||||
|
|
||||||
abstract class UIState implements Built<UIState, UIStateBuilder> {
|
abstract class UIState implements Built<UIState, UIStateBuilder> {
|
||||||
|
|
||||||
factory UIState() {
|
factory UIState({bool enableDarkMode}) {
|
||||||
return _$UIState._(
|
return _$UIState._(
|
||||||
selectedCompanyIndex: 0,
|
selectedCompanyIndex: 0,
|
||||||
currentRoute: LoginScreen.route,
|
currentRoute: LoginScreen.route,
|
||||||
enableDarkMode: false,
|
enableDarkMode: enableDarkMode ?? false,
|
||||||
productUIState: ProductUIState(),
|
productUIState: ProductUIState(),
|
||||||
clientUIState: ClientUIState(),
|
clientUIState: ClientUIState(),
|
||||||
invoiceUIState: InvoiceUIState(),
|
invoiceUIState: InvoiceUIState(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue