@@ -12,6 +12,11 @@ class MyApp extends StatefulWidget {
12
12
_MyAppState createState () => new _MyAppState ();
13
13
}
14
14
15
+ enum DialogDemoAction {
16
+ cancel,
17
+ connect,
18
+ }
19
+
15
20
class _MyAppState extends State <MyApp > {
16
21
List <RouteItem > items;
17
22
String _serverAddress = '192.168.31.152' ;
@@ -59,6 +64,55 @@ class _MyAppState extends State<MyApp> {
59
64
});
60
65
}
61
66
67
+ void showDemoDialog <T >({BuildContext context, Widget child}) {
68
+ showDialog <T >(
69
+ context: context,
70
+ builder: (BuildContext context) => child,
71
+ ).then <void >((T value) {
72
+ // The value passed to Navigator.pop() or null.
73
+ if (value != null ) {
74
+ if (value == DialogDemoAction .connect) {
75
+ prefs.setString ('server' , _serverAddress);
76
+ Navigator .push (
77
+ context,
78
+ MaterialPageRoute (
79
+ builder: (BuildContext context) =>
80
+ CallSample (ip: _serverAddress)));
81
+ }
82
+ }
83
+ });
84
+ }
85
+
86
+ _showAddressDialog (context) {
87
+ showDemoDialog <DialogDemoAction >(
88
+ context: context,
89
+ child: new AlertDialog (
90
+ title: const Text ('Enter server address:' ),
91
+ content: TextField (
92
+ onChanged: (String text) {
93
+ setState (() {
94
+ _serverAddress = text;
95
+ });
96
+ },
97
+ decoration: InputDecoration (
98
+ hintText: _serverAddress,
99
+ ),
100
+ textAlign: TextAlign .center,
101
+ ),
102
+ actions: < Widget > [
103
+ new FlatButton (
104
+ child: const Text ('CANCEL' ),
105
+ onPressed: () {
106
+ Navigator .pop (context, DialogDemoAction .cancel);
107
+ }),
108
+ new FlatButton (
109
+ child: const Text ('CONNECT' ),
110
+ onPressed: () {
111
+ Navigator .pop (context, DialogDemoAction .connect);
112
+ })
113
+ ]));
114
+ }
115
+
62
116
_initItems () {
63
117
items = < RouteItem > [
64
118
RouteItem (
@@ -74,40 +128,7 @@ class _MyAppState extends State<MyApp> {
74
128
title: 'P2P Call Sample' ,
75
129
subtitle: 'P2P Call Sample.' ,
76
130
push: (BuildContext context) {
77
- showDialog <Null >(
78
- context: context,
79
- builder: (BuildContext context) {
80
- return SimpleDialog (
81
- title: const Text ('Please input server address.' ),
82
- children: < Widget > [
83
- TextField (
84
- onChanged: (String text) {
85
- setState (() {
86
- _serverAddress = text;
87
- });
88
- },
89
- decoration: InputDecoration (
90
- hintText: _serverAddress,
91
- ),
92
- textAlign: TextAlign .center,
93
- ),
94
- SimpleDialogOption (
95
- onPressed: () {},
96
- child: RaisedButton (
97
- onPressed: () {
98
- prefs.setString ('server' , _serverAddress);
99
- Navigator .push (
100
- context,
101
- MaterialPageRoute (
102
- builder: (BuildContext context) =>
103
- CallSample (ip: _serverAddress)));
104
- },
105
- child: const Text ('Connect Server' ),
106
- ),
107
- ),
108
- ],
109
- );
110
- });
131
+ _showAddressDialog (context);
111
132
}),
112
133
];
113
134
}
0 commit comments