flutter.widget

AlertDialog

paulaner80 2021. 4. 13. 10:48
반응형

 

 

 

 

Dialog를 띄우려면 showDialog를 호출해야함.

 

Dialog에 닫기 버튼 추가

       TextButton(onPressed: (){
          Navigator.of(context).pop();
         }, child: Text("Close"))

 

전체소스

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return
      SafeArea(
        child: Center(
          child: Column(
            children: [
              ElevatedButton(
                onPressed: (){
                  showDialog(
                      context: context,
                      builder: (context){
                        return AlertDialog(
                          title:Text("Alert Dialog"),
                          content: Text("content"),
                          actions: [
                            TextButton(onPressed: (){
                              Navigator.of(context).pop();
                            }, child: Text("Close"))
                          ],
                        );
                      });
                }
                , child: Text("alertDiaog")),
            ],
          ),
        )
      );
  }
}

 

'flutter.widget' 카테고리의 다른 글

RadioListTile  (0) 2021.05.14
Drawer  (0) 2021.04.14
RefreshIndicator  (0) 2021.04.08
FractionallySizedBox  (0) 2021.04.06
image  (0) 2020.11.30