Repository navigation
Expand file tree
/
Copy pathmain.dart
More file actions
68 lines (58 loc) · 1.75 KB
/
Copy pathmain.dart
File metadata and controls
68 lines (58 loc) · 1.75 KB
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
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:doubanapp/widgets/bottom_drag_widget.dart';
import 'package:doubanapp/pages/splash/splash_widget.dart';
void main() {
runApp(MyApp());
if (Platform.isAndroid) {
//设置Android头部的导航栏透明
SystemUiOverlayStyle systemUiOverlayStyle =
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return RestartWidget(
child: MaterialApp(
theme: ThemeData(backgroundColor: Colors.white),
home: Scaffold(
body: SplashWidget(),
),
),
);
}
}
///这个组件用来重新加载整个child Widget的。当我们需要重启APP的时候,可以使用这个方案
///https://stackoverflow.com/questions/50115311/flutter-how-to-force-an-application-restart-in-production-mode
class RestartWidget extends StatefulWidget {
final Widget child;
RestartWidget({Key key, @required this.child})
: assert(child != null),
super(key: key);
static restartApp(BuildContext context) {
final _RestartWidgetState state =
context.findAncestorStateOfType<_RestartWidgetState>();
state.restartApp();
}
@override
_RestartWidgetState createState() => _RestartWidgetState();
}
class _RestartWidgetState extends State<RestartWidget> {
Key key = UniqueKey();
void restartApp() {
setState(() {
key = UniqueKey();
});
}
@override
Widget build(BuildContext context) {
return Container(
key: key,
child: widget.child,
);
}
}