forked from bluemix/Tourism-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
97 lines (83 loc) · 2.93 KB
/
main.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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:tourism_demo/i18n/translations.dart';
import 'package:tourism_demo/i18n/translations_delegate.dart';
import 'package:tourism_demo/redux/app/app_state.dart';
import 'package:tourism_demo/redux/store.dart';
import 'package:tourism_demo/styles/app_theme.dart';
import 'package:tourism_demo/ui/main_page.dart';
Future<Null> main() async {
// ignore: deprecated_member_use
// MaterialPageRoute.debugEnableFadingRoutes = true;
var store = await createStore();
runApp(TourismApp(store));
}
class TourismApp extends StatefulWidget {
TourismApp(this.store);
final Store<AppState> store;
@override
_TourismAppState createState() => _TourismAppState();
}
class _TourismAppState extends State<TourismApp> with SingleTickerProviderStateMixin {
Locale prevLocale;
AnimationController fadeController;
@override
void initState() {
fadeController = new AnimationController(
duration: const Duration(milliseconds: 1000),
debugLabel: 'preview banner',
vsync: this,
);
super.initState();
}
@override
void dispose() {
fadeController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return StoreProvider<AppState>(
store: widget.store,
child: new StoreConnector<AppState, AppState>(
converter: (store) => store.state,
ignoreChange: (store) => prevLocale == store.appLocale,
builder: (context, appState) {
if (prevLocale == null) {
prevLocale = appState.appLocale;
}
//
bool shouldFade = prevLocale != appState.appLocale;
if (shouldFade) {
prevLocale = appState.appLocale;
}
return Container(
color: Theme.of(context).backgroundColor,
child: FadeTransition(
child: MaterialApp(
onGenerateTitle: (BuildContext context) => Translations.of(context).title,
theme: AppTheme.theme,
localizationsDelegates: [
const TranslationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
locale: appState.appLocale,
supportedLocales: widget.store.state.supportedLocales,
home: const MainPage(),
),
opacity: new CurvedAnimation(
parent: fadeController
..reset()
..forward(),
curve: const Interval(0.0, 1.0, curve: Curves.ease),
)),
);
},
));
}
}