I'm trying to create a SimpleDialog
after a tap on the FloatingActionButton
, however when pressing that button nothing happens.
What was I doing wrong?
import "package:flutter/material.dart"; void main() { runApp(new ControlleApp()); } class ControlleApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( home: new HomePage(), ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) => new Scaffold( appBar: new AppBar( backgroundColor: new Color(0xFF26C6DA), ), floatingActionButton: new FloatingActionButton( tooltip: 'Add', child: new Icon(Icons.add), backgroundColor: new Color(0xFFF44336), onPressed: (){ new SimpleDialog( title: new Text('Test'), children: <Widget>[ new RadioListTile( title: new Text('Testing'), value: null, groupValue: null, onChanged: (value) {}, ) ], ); } ), ); }
In its on the pressed property, we have to use the showDialog widget of flutter. It takes context and a builder. In builder, we provide the AlertDialog widget with title, content(Description of a title), and actions (Yes or no buttons), and our alert dialog box is ready to use.
Use a Container where you can specify width and height, then use a RawMaterialButton, like this: myFabButton = Container( width: 200.0, height: 200.0, child: new RawMaterialButton( shape: new CircleBorder(), elevation: 0.0, child: Icon( Icons.
I noticed the accepted answer is using child
for showDialog
which is actually deprecated, so I would recommend avoiding it. You should be using builder
instead, I've provided an example:
onPressed: () { showDialog( context: context, builder: (_) => AlertDialog( title: Text('Dialog Title'), content: Text('This is my content'), ) ); }
You need to wrap this on a show action dialog.
showDialog(context: context, builder: (BuildContext context) { return new AlertDialog( title: new Text("My Super title"), content: new Text("Hello World"), ); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With