Flutter13.Dialog

ex:

import 'dart:math';

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DialogApp',
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            SimpleDialog(
              title: Text('Dialog title'),//Dialog的标题
              children: <Widget>[
                SimpleDialogOption(
                  child: Text('Choice 1'),
                  onPressed: (){
                    print('Choice 1');
                  },
                ),
                SimpleDialogOption(
                  child: Text('Choice 2'),
                  onPressed: (){
                    print('Choice 2');
                  },
                )
              ],
            ),
            RaisedButton(//按钮弹出Dialog
              child: Text('Delete'),
              onPressed: () {
                showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        title: Text('Notice'),
                        content: SingleChildScrollView(
                          child: ListBody(
                            children: <Widget>[
                              Text('Agree to Delete?'),
                              Text('Make sure your choice!'),
                            ],
                          ),
                        ),
                        actions: <Widget>[
                          FlatButton(
                            child: Text('Agree'),
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                          ),
                          FlatButton(
                            child: Text('Cancel'),
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                          ),
                        ],
                      );
                    }
                  );
              },
            ),
          ],
        ),
      ),
    );
  }
}


输出:

猜你喜欢

转载自blog.csdn.net/augfun/article/details/106972893