File tree Expand file tree Collapse file tree 2 files changed +44
-8
lines changed Expand file tree Collapse file tree 2 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -14,20 +14,55 @@ void main() {
14
14
}
15
15
}
16
16
17
- DragController controller = DragController ();
18
-
19
17
class MyApp extends StatelessWidget {
20
18
// This widget is the root of your application.
21
19
22
20
@override
23
21
Widget build (BuildContext context) {
24
- return MaterialApp (
25
- theme: ThemeData (backgroundColor: Colors .white),
26
- home: Scaffold (
27
- resizeToAvoidBottomPadding: false ,
28
- body: SplashWidget (),
22
+ return RestartWidget (
23
+ child: MaterialApp (
24
+ theme: ThemeData (backgroundColor: Colors .white),
25
+ home: Scaffold (
26
+ resizeToAvoidBottomPadding: false ,
27
+ body: SplashWidget (),
28
+ ),
29
29
),
30
30
);
31
31
}
32
32
}
33
33
34
+ ///这个组件用来重新加载整个child Widget的。当我们需要重启APP的时候,可以使用这个方案
35
+ class RestartWidget extends StatefulWidget {
36
+ final Widget child;
37
+
38
+ RestartWidget ({Key key, @required this .child})
39
+ : assert (child != null ),
40
+ super (key: key);
41
+
42
+ static restartApp (BuildContext context) {
43
+ final _RestartWidgetState state =
44
+ context.ancestorStateOfType (const TypeMatcher <_RestartWidgetState >());
45
+ state.restartApp ();
46
+ }
47
+
48
+ @override
49
+ _RestartWidgetState createState () => _RestartWidgetState ();
50
+ }
51
+
52
+ class _RestartWidgetState extends State <RestartWidget > {
53
+ Key key = UniqueKey ();
54
+
55
+ void restartApp () {
56
+ setState (() {
57
+ key = UniqueKey ();
58
+ });
59
+ }
60
+
61
+ @override
62
+ Widget build (BuildContext context) {
63
+ return Container (
64
+ key: key,
65
+ child: widget.child,
66
+ );
67
+ }
68
+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import 'package:flutter/cupertino.dart';
5
5
import 'package:flutter_cache_manager/flutter_cache_manager.dart' ;
6
6
import 'package:shared_preferences/shared_preferences.dart' ;
7
7
import 'package:douban_app/constant/cache_key.dart' ;
8
-
8
+ import 'package:douban_app/main.dart' ;
9
9
typedef VoidCallback = void Function ();
10
10
11
11
///个人中心
@@ -194,6 +194,7 @@ class _UseNetDataWidgetState extends State<UseNetDataWidget> {
194
194
Navigator .of (context).pop ();
195
195
},),
196
196
FlatButton (child: Text ('现在重启' ),onPressed: (){
197
+ RestartWidget .restartApp (context);
197
198
Navigator .of (context).pop ();
198
199
},)
199
200
],);
You can’t perform that action at this time.
0 commit comments