Pengertian Simple Dialog in Flutter

Simple Dialog merupakan salah satu jenis dari function showdialog. Perbedaan antara alertdialog dengan simple dialog hanya ada pada action barnya, dimana simpledialog tidak memiliki action button. Simple dialog biasanya digunakan untuk membuat popup yang berisi form atau opsi-opsi lainnya.

Contoh Code nya :


import 'package:flutter/material.dart';

void main (){
  runApp(new MaterialApp(home: MyApp()));
}

class MyApp extends StatefulWidget{
  @override
   _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp>{
  SimpleDialog sd;
  void dialog(){
    sd = new SimpleDialog( title: new Text('Pilih salah satu'),
      children: <Widget>[
        new SimpleDialogOption(child: new Text('Jakarta'),
        onPressed: (){ print('Jakarta');},),

        new SimpleDialogOption( child: new Text('Padang'),
        onPressed: (){print('Padang');},),

        new SimpleDialogOption( child: new Text('Close'),
        onPressed: (){Navigator.pop(context);
        },),
      ],
    );
    showDialog(context: context,child: sd);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(appBar: AppBar(title: new Text('Notification Widget'),
    backgroundColor: Colors.blue,),

    body: new Center( child: new RaisedButton(onPressed: (){
      dialog();},
    child: new Text('Show Simple Dialog'),
    ),),);
  }
}

Hasil running:

C:\Users\acer\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Screenshot_2021-02-21-21-59-23-54_1a1bb06d919e4ad14021182c4efbb56a.jpg

C:\Users\acer\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Screenshot_2021-02-21-21-59-29-36_1a1bb06d919e4ad14021182c4efbb56a.jpg

Leave a Comment