尝试使用浮动代码显示对话框,但未显示错误,但对话框未显示

问题描述 投票:0回答:1

我正在为大学制作一个简单的Notification应用程序,我已经在底部导航栏中添加了一个浮动按钮,该按钮应该显示一个对话框,我可以在其中输入要发送的文本,但是当我按下浮动动作按钮时,对话框不会出现。已为onpressed添加了一个功能,但是当我运行代码时,什么也没发生,代码没有显示任何错误,只是不起作用,我在下面添加了代码

import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(notification());
}

class notification extends StatefulWidget {
  @override
  _notificationState createState() => _notificationState();
}

class _notificationState extends State<notification> {

    Future<bool> addDialog(BuildContext context)async{
      return showDialog(
        context:context,
        barrierDismissible: false,
        builder: (BuildContext context){

          return AlertDialog(
              title: Text('Add Data',style: TextStyle(fontSize: 15),),
              content: Column(
                children: <Widget>[
                  TextField(
                    decoration: InputDecoration(hintText: 'Enter the notification'),
                    onChanged: (value){

                    },
                  )
                ],
              ),

              actions: <Widget>[
                FlatButton(onPressed: null, child: Text('Send'))
              ],
          );

        }
      );
    }


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
     home: Scaffold(
       appBar: AppBar(
         title: Text('Notifications.',style: TextStyle(fontSize: 25,fontWeight: FontWeight.bold,color: Colors.black),),
         elevation: 0.0,
         backgroundColor: Colors.transparent,
       ),
       bottomNavigationBar: Row(
         mainAxisAlignment: MainAxisAlignment.spaceEvenly,
         children: <Widget>[
            Container(
             child: FloatingActionButton.extended(onPressed: (){
               addDialog(context);
             },
            icon:Icon(Icons.add,color: Colors.black,),
            label: Text('Add',style: TextStyle(color: Colors.black,)),
            backgroundColor: Colors.yellow[600],

            ),
            padding: EdgeInsets.fromLTRB(0, 0, 0, 20),
            )
         ],
       ),

       body: Center(
         child: Container(

         ),
       )

     ),
    );
  }
}

“在此处输入图像描述”

flutter flutter-layout google-apps
1个回答
0
投票
您可以使用“ MaterialApp”。

runApp(MaterialApp(home: notification()));

© www.soinside.com 2019 - 2024. All rights reserved.