Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - SimpleDialog in FloatingActionButton

Tags:

flutter

dart

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) {},             )           ],         );       }          ),       ); } 
like image 950
rafaelcb21 Avatar asked Jun 20 '17 14:06

rafaelcb21


People also ask

How do you show dialog box in Flutter?

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.

How do you change fab size in Flutter?

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.


2 Answers

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'),         )     ); } 
like image 163
Mark O'Sullivan Avatar answered Oct 12 '22 13:10

Mark O'Sullivan


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"),    ); } 
like image 31
Alexi Coard Avatar answered Oct 12 '22 12:10

Alexi Coard