Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

the ShowDialog is not Working in Flutter Android

I’m starting on Flutter. Today, I learned how to coding a showDialog, but it doesn’t work. i have tried to write it again and again but nothing affects… here’s my code:


import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(home: Scaffold(appBar: AppBar(), body: MyHome())));
}

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

  @override
  State<MyHome> createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> {
  @override
  void MyDialog() {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("title"),
            content: Text("Thanks to clock"),
            actions: <Widget>[
              TextButton(
                onPressed: () {},
                child: Text("close"),
              )
            ],
          );
        });
  }

  Widget build(BuildContext context) {
    return TextButton(
      onPressed: () {},
      child: Text("Click On me!"),
    );
  }
}

Please help me! Thanks…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You did not call MyDialog anywhere in the code.

updated code:

import 'package:flutter/material.dart';

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

  @override
  State<SignUpScreen> createState() => _SignUpScreenState();
}

class _SignUpScreenState extends State<SignUpScreen> {
  @override
  void MyDialog() {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text("title"),
            content: Text("Thanks to clock"),
            actions: <Widget>[
              TextButton(
                onPressed: () {},
                child: Text("close"),
              )
            ],
          );
        });
  }

  Widget build(BuildContext context) {
    return TextButton(
      onPressed: () {
        MyDialog();
      },
      child: Text("Click On me!"),
    );
  }
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading