Flutter 自定义弹出层

import 'package:flutter/material.dart';

class Toast extends StatefulWidget {
     
  @override
  _ToastState createState() => _ToastState();
}

class _ToastState extends State {
     
  @override
  Widget build(BuildContext context) {
     
    Future myDialog(context){
     
  return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
     
            return GestureDetector(							// 手势处理事件
              onTap: (){
     
                Navigator.of(context).pop();				//退出弹出框
              },
              child: Container(								//弹出框的具体事件
                child: Material(
                  color: Color.fromRGBO(0, 0, 0, 0.1),
                  child: Center(
                    child: Text('具体操作',style:TextStyle(color: Colors.white),),
                  ),
                ),
              )
            );
            
        },
    );
}
    return Scaffold(
        body: Container(
            child: Center(
                child: GestureDetector(
                  onTap: (){
     
                      myDialog(context);
                  },
                //  点击执行弹窗
                 child: Center(
                   child: Text("弹窗"),
                 ), 
                ),
            ),     
    ),
    );
  }
}

学习自定义弹出层

你可能感兴趣的:(Flutter学习笔记)