-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp_homepage.dart
123 lines (109 loc) · 3.74 KB
/
app_homepage.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import 'package:assorted_layout_widgets/assorted_layout_widgets.dart';
import 'package:async_redux/async_redux.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:i18n_extension/i18n_extension.dart';
import 'package:mobile_app_flutter_redux/client/infra/app_state.dart';
import 'package:mobile_app_flutter_redux/client/infra/basic/ACTION_process_lifecycle_change.dart';
import 'package:mobile_app_flutter_redux/client/infra/basic/client.dart';
import 'package:mobile_app_flutter_redux/client/infra/navigation/app_routes.dart';
import 'package:mobile_app_flutter_redux/client/infra/theme/app_themes.dart';
import 'package:themed/themed.dart';
import 'business.dart';
class AppHomePage extends StatelessWidget {
const AppHomePage();
static const I18nWidgetId = "I18nWidget";
@override
Widget build(BuildContext context) {
//
var navigatorRoutesWrapper = (BuildContext context, Widget? child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaler: const TextScaler.linear(1.0)),
child: Box(
child: I18n(
id: I18nWidgetId,
// initialLocale: const Locale("en", "US"),
child: (child == null) //
? const Box()
:
// This dialog gets error messages from AsyncRedux, and shows a dialog.
UserExceptionDialog<AppState>(child: child),
),
),
);
};
return Themed(
currentTheme: Business.store.state.ui.isDarkMode ? darkTheme : null,
child: StoreProvider<AppState>(
store: Business.store,
child: AppLifecycleManager(
child: MaterialApp(
theme: ThemeData(
primaryColor: Colors.green.shade800,
colorScheme: ThemeData().colorScheme.copyWith(secondary: Colors.green.shade600),
),
title: "Demo App",
navigatorKey: Client.navigatorKey,
debugShowCheckedModeBanner: false,
builder: navigatorRoutesWrapper,
initialRoute: '/',
navigatorObservers: [
Client.routeObserver,
//
// TODO: Hook for analytics.
// FirebaseAnalyticsObserver(analytics: Dao.firebaseAnalytics),
],
localizationsDelegates: AppLocalizations.delegates,
supportedLocales: AppLocalizations.supportedLocales(),
onGenerateRoute: AppRoutes.onGenerateRoute,
),
),
),
);
}
}
class AppLifecycleManager extends StatefulWidget {
//
final Widget child;
const AppLifecycleManager({
super.key,
required this.child,
});
@override
_AppLifecycleManagerState createState() => _AppLifecycleManagerState();
}
class _AppLifecycleManagerState extends State<AppLifecycleManager> with WidgetsBindingObserver {
//
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState lifecycle) {
Business.store.dispatch(ProcessLifecycleChange_Action(lifecycle));
}
@override
Widget build(BuildContext context) => widget.child;
}
class AppLocalizations {
//
static List<LocalizationsDelegate> get delegates => [
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
];
static List<Locale> supportedLocales() {
return [
const Locale('en', 'US'),
const Locale('sp', 'ES'),
];
}
}