1+ import 'package:flutter/material.dart' ;
2+
3+ class Index extends StatefulWidget {
4+ @override
5+ _IndexState createState () => _IndexState ();
6+ }
7+
8+ class _IndexState extends State <Index > {
9+
10+ List Option = ['A' , 'B' , 'C' ];
11+ String _choose = 'Nothing' ;
12+
13+ Future _openSimpleDialog () async {
14+ final option = await showDialog (
15+ context: context,
16+ builder: (BuildContext context) {
17+ return SimpleDialog (
18+ title: Text ('SimpleDialog' ),
19+ titlePadding: EdgeInsets .fromLTRB (24.0 , 24.0 , 24.0 , 0.0 ),
20+ contentPadding: EdgeInsets .fromLTRB (0.0 , 12.0 , 0.0 , 16.0 ),
21+ children: List .generate (3 , (index) {
22+ return SimpleDialogOption (
23+ child: Text ('Option ${Option [index ]}' ),
24+ onPressed: (){
25+ Navigator .pop (context, Option [index]);
26+ },
27+ );
28+ }),
29+ );
30+ }
31+ );
32+ switch (option) {
33+ case "A" :
34+ setState (() {
35+ _choose = 'A' ;
36+ });
37+ break ;
38+ case "B" :
39+ setState (() {
40+ _choose = 'B' ;
41+ });
42+ break ;
43+ case "C" :
44+ setState (() {
45+ _choose = 'C' ;
46+ });
47+ break ;
48+ default :
49+ }
50+ }
51+
52+
53+ @override
54+ Widget build (BuildContext context) {
55+ return Scaffold (
56+ appBar: AppBar (title: Text ('SimpleDialog' ),),
57+ body: Center (
58+ child: Text ('你的选择是:$_choose ' )
59+ ),
60+ floatingActionButton: FloatingActionButton (
61+ onPressed: _openSimpleDialog,
62+ child: Icon (Icons .branding_watermark, color: Colors .white, size: 30.0 ,),
63+ backgroundColor: Theme .of (context).primaryColor,
64+ ),
65+ );
66+ }
67+ }
0 commit comments