highdragon
highdragon

Reputation: 108

ShowDialog box is always fullscreen in Flutter?

I want to create a show dialog box that will act as a disclosure. The one that I've used now gives me a fullscreen dialog, which I don't want. I want it to take the least amount of space that is needed. enter image description here

This disclosure should pop up immediately as soon as the app opens, therefore, I've added this in the init state. Can someone please tell me how to minimise the size?

The code is as below.`

  class LandingScreen extends StatefulWidget {
  static const routeName = "/landing_screen";
  @override
  _LandingScreenState createState() => _LandingScreenState();}

  class _LandingScreenState extends State<LandingScreen> {
       bool _introDone = false;

     @override
      void initState() {
       // TODO: implement initState
      super.initState();
      SharedPreferences.getInstance().then((value) {
        final introDone = value.getBool("introDone") ?? false;
        setState(() {
          _introDone = introDone;
        });
        !_introDone
            ? showDialog(
          barrierDismissible: true,
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: const Text("DISCLOSURE"),
              content: Column(
                children: <Widget>[
                  const Text("This app collects location data to enable location tracking in order to provide location based reminders. This include collecting location data even when the app is running in the background. The data collected will be handled according to the terms of our Privacy notice"),
              ],
              ),
              actions: <Widget>[
                TextButton(
                    style: TextButton.styleFrom(primary: Colors.blue),
                    onPressed: () {},
                    child: const Text("GOT IT")),
              ],
            );
          },


        ):null;
      });


    @override
    Widget build(BuildContext context) {
      return Containter();
    }
  }

Upvotes: 4

Views: 2798

Answers (1)

Ignacior
Ignacior

Reputation: 957

Your problem is in the Column widget. You have to changethe mainAxisSize to min.

builder: (BuildContext context) {
            return AlertDialog(
              title: const Text("DISCLOSURE"),
              content: Column(
                mainAxisSize: MainAxisSize.min, // <---
                children: <Widget>[
                  const Text("This app collects location data to enable location tracking in order to provide location based reminders. This include collecting location data even when the app is running in the background. The data collected will be handled according to the terms of our Privacy notice"),
              ],
              ),
              actions: <Widget>[
                TextButton(
                    style: TextButton.styleFrom(primary: Colors.blue),
                    onPressed: () {},
                    child: const Text("GOT IT")),
              ],
            );
          },

Upvotes: 6

Related Questions