Punreach Rany
Punreach Rany

Reputation: 3690

Flutter & AlertDialog : How do I align it to bottom? How I make 2 Alert Dialogs like this pictures?

Flutter & AlertDialog : How do I align it to bottom? How I make 2 Alert Dialogs like this pictures?Please have a lot at this picture.

enter image description here

showDialog(
                                context: context,
                                builder: (BuildContext context) {
                                  double width =
                                      MediaQuery.of(context).size.width;
                                  double height =
                                      MediaQuery.of(context).size.height;
                                  return AlertDialog(
                                    backgroundColor: Colors.transparent,
                                    contentPadding: EdgeInsets.zero,
                                    title: Center(
                                        child: Text("Evaluation our APP")),
                                    content: Container(

                                       // What Should I write here?

                                    )
                                },
                              );

Upvotes: 4

Views: 6551

Answers (3)

Dhruvam Sharma
Dhruvam Sharma

Reputation: 1793

Pretty late to the conversation but adding the solution here just for future reference:

builder: (context) => AlertDialog(
    alignment: Alignment.bottomCenter,
    contentPadding: const EdgeInsets.all(0),
    content: LocationUnavailableWidget(
      onLocationEnabled: () {
        onLocationEnabled();
        blocState.add(GetLocationPermissionEvent());
        Navigator.of(context).pop();
      },
    ),
  ),

The alignment property allows displaying the dialog at your desired location.

enter image description here

Upvotes: 3

Wesley Chang
Wesley Chang

Reputation: 1741

here is my answer, pure widget without create AlertDialog:


    final content = Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: const BorderRadius.all(Radius.circular(10.0)),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              TextButton(onPressed: () {}, child: Text("a"),),
              Divider(height: 1,),
              TextButton(onPressed: () {}, child: Text("b"),),
              Divider(height: 1,),
              TextButton(onPressed: () {}, child: Text("c"),),
            ],
          ),
        ),
        SizedBox(
          height: 10,
        ),
        Container(
          width: double.infinity,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius:
            const BorderRadius.all(Radius.circular(10.0)),
          ),
          child: TextButton(onPressed: () {}, child: Text("d"),),
        ),
        SizedBox(
          height: 40,
        ),
      ],
    );

    showDialog(
      context: context,
      builder: (ctx) {
        return FractionallySizedBox(
          widthFactor: 0.9,
          child: Material(
            type: MaterialType.transparency,
            child: content,
          ),
        );
      }
    );

have to add Material because of text drawing error.

Upvotes: 3

Thắng Mai
Thắng Mai

Reputation: 1061

Here is one of the solutions:

          showDialog(
            context: context,
            builder: (BuildContext context) {
              double width = MediaQuery.of(context).size.width;
              double height = MediaQuery.of(context).size.height;
              return AlertDialog(
                  backgroundColor: Colors.transparent,
                  contentPadding: EdgeInsets.zero,
                  elevation: 0.0,
                  // title: Center(child: Text("Evaluation our APP")),
                  content: Column(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Container(
                        padding: const EdgeInsets.all(8.0),
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius:
                                const BorderRadius.all(Radius.circular(10.0))),
                        child: Column(
                          children: [
                            Text("a"),
                            Divider(),
                            Text("b"),
                            Divider(),
                            Text("c"),
                          ],
                        ),
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      Container(
                        padding: const EdgeInsets.all(8.0),
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius:
                                const BorderRadius.all(Radius.circular(10.0))),
                        child: Center(child: Text("d")),
                      )
                    ],
                  ));
            },
          );

Upvotes: 5

Related Questions