Re: How to display a dialog after page loads using showDialog

1,645 views
Skip to first unread message

Eugenio Tesio

unread,
May 15, 2018, 6:48:39 AM5/15/18
to Adam Zedan, Flutter Dev
Try this:

    @override
    Widget build(BuildContext context)
    {
        showDialog(context: context, builder:(BuildContext context){ return  myWidgets.getBusyDialog();});
        return new Scaffold(
            body: new Container(
                child: new Column(
                    children: <Widget>[
                        new Text(getText()),
                    ],
                    ),
                ),
            );

    }

El lun., 14 may. 2018 a las 22:16, Adam Zedan (<zeda...@gmail.com>) escribió:
I would like to display a dialog using showDialog as soon as the page loads. 

I currently have something like this 


class TestActive extends StatefulWidget
{
    TestActive();

    @override
    TestActiveState createState() => new TestActiveState();
}

class TestActiveState extends State<TestActive> with SingleTickerProviderStateMixin,CommonMixin
{

    TestActiveState()
    {

    }

    @override
    void initState()
    {
        super.initState();
    }

    @override
    void dispose() {
        super.dispose();
    }

    String getText()
    {
        showDialog(context: context, builder:(BuildContext context){ return  myWidgets.getBusyDialog();});
        return "Hello";
    }

    @override
    Widget build(BuildContext context)
    {
        return new Scaffold(
            body: new Container(
                child: new Column(
                    children: <Widget>[
                        new Text(getText()),
                    ],
                    ),
                ),
            );

    }
}

In the above code I get the error :
flutter: The following assertion was thrown building TestActive(dirty, state: TestActiveState#c01af):
flutter: setState() or markNeedsBuild() called during build.
flutter: This Overlay widget cannot be marked as needing to build because the framework is already in the
flutter: process of building widgets. A widget can be marked as needing to be built during the build phase
flutter: only if one of its ancestors is currently building. This exception is allowed because the framework
flutter: builds parent widgets before children, which means a dirty descendant will always be built.
flutter: Otherwise, the framework might not visit this widget during this build phase.
flutter: The widget on which setState() or markNeedsBuild() was called was:
flutter:   Overlay-[LabeledGlobalKey<OverlayState>#96e49](state: OverlayState#7aab6(entries:
flutter:   [OverlayEntry#ff9bb(opaque: false; maintainState: false), OverlayEntry#ee5ca(opaque: false;

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Eugenio Tesio
Zetus - Soluciones Empresariales
División Sistemas
(+549) 3564-15-599945
San Francisco - 2400
Pcia de Córdoba - Argentina



Reply all
Reply to author
Forward
0 new messages