Flutter Tutorials

Flutter app development tutorials


flutter – AlertDialog height

main.dart


import 'package:flutter/material.dart';

void main() => runApp(const FlutterExample());

class FlutterExample extends StatelessWidget {
  const FlutterExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Example',
        theme: ThemeData(primarySwatch: Colors.pink),
        home: const StateExample()
    );
  }
}

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

  @override
  _StateExampleState createState() => _StateExampleState();
}

class _StateExampleState extends State<StateExample> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: const Color(0xFFF5F5F5),
        appBar: AppBar(
            title: const Text("Flutter - AlertDialog Height")
        ),
        body: bodyContent()
    );
  }


  bodyContent(){
    return Center(
      child: ElevatedButton(
        child: const Text("Show Dialog"),
        onPressed: (){
          showAlertDialog();
        },
      ),
    );
  }


  showAlertDialog(){
    showDialog(
        context: context,
        builder: (BuildContext context){
          return  Stack(
            clipBehavior: Clip.none, alignment: Alignment.center,
            children: <Widget>[
              Container(
                  width: MediaQuery.of(context).size.width - 16,
                  height: 500,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8),
                      color: Colors.grey[100]
                  ),
                  padding: const EdgeInsets.fromLTRB(16, 16, 16, 4),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      const Text(
                        "Agree with the terms?",
                        style: TextStyle(
                          decoration: TextDecoration.none,
                          color: Colors.black,
                          fontSize: 22,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      const SizedBox(height: 30),
                      const Expanded(
                        child: SingleChildScrollView(
                          scrollDirection: Axis.vertical,
                          child: Text(
                            "Lorem Ipsum is simply dummy text of the"
                                " printing and typesetting industry."
                                " Lorem Ipsum has been the industry's"
                                " standard dummy text ever since the"
                                " 1500s, when an unknown printer took"
                                " a galley of type and scrambled it"
                                " to make a type specimen book. It"
                                " has survived not only five"
                                " centuries, but also the leap into"
                                " electronic typesetting, remaining"
                                " essentially unchanged. It was"
                                " popularised in the 1960s with the"
                                " release of Letraset sheets containing"
                                " Lorem Ipsum passages, and more recently"
                                " with desktop publishing software like"
                                " Aldus PageMaker including"
                                " versions of Lorem Ipsum.",
                            style: TextStyle(
                              fontSize: 20,
                              fontStyle: FontStyle.normal,
                              decoration: TextDecoration.none,
                              color: Colors.black87,
                            ),
                          ),
                        ) ,
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          TextButton(
                              onPressed: (){
                                Navigator.pop(context);
                              },
                              child: const Text("No")
                          ),
                          TextButton(
                              onPressed: (){
                                Navigator.pop(context);
                              },
                              child: const Text("Yes")
                          )
                        ],
                      )
                    ],
                  )
              )
            ],
          );
        }
    );
  }
}

More flutter tutorials



About Me

Flutter Developer

Design a site like this with WordPress.com
Get started