@@ -12,6 +12,11 @@ class MyApp extends StatefulWidget {
1212 _MyAppState createState () => new _MyAppState ();
1313}
1414
15+ enum DialogDemoAction {
16+ cancel,
17+ connect,
18+ }
19+
1520class _MyAppState extends State <MyApp > {
1621 List <RouteItem > items;
1722 String _serverAddress = '192.168.31.152' ;
@@ -59,6 +64,55 @@ class _MyAppState extends State<MyApp> {
5964 });
6065 }
6166
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+
62116 _initItems () {
63117 items = < RouteItem > [
64118 RouteItem (
@@ -74,40 +128,7 @@ class _MyAppState extends State<MyApp> {
74128 title: 'P2P Call Sample' ,
75129 subtitle: 'P2P Call Sample.' ,
76130 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);
111132 }),
112133 ];
113134 }
0 commit comments