Custom Dialogs in Flutter
link: https://medium.flutterdevs.com/custom-dialog-in-flutter-7ca5c2a8d33a
dialog.dart code:
import 'package:custom_dialog_flutter_demo/custom_dialog_box.dart'; import 'package:flutter/material.dart';class Dialogs extends StatefulWidget { @override _DialogsState createState() => _DialogsState(); }class _DialogsState extends State<Dialogs> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Custom Dialog In Flutter"), centerTitle: true, automaticallyImplyLeading: false, ), body: Container( child: Center( child: RaisedButton( onPressed: (){ showDialog(context: context, builder: (BuildContext context){ return CustomDialogBox( title: "Custom Dialog Demo", descriptions: "Hii all this is a custom dialog in flutter and you will be use in your flutter applications", text: "Yes", ); } ); }, child: Text("Custom Dialog"),), ), ), ); } }
CustomDialogBox.dart:
import 'dart:ui'; import 'package:custom_dialog_flutter_demo/constants.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class CustomDialogBox extends StatefulWidget { final String title, descriptions, text; final Image img; const CustomDialogBox({Key key, this.title, this.descriptions, this.text, this.img}) : super(key: key); @override _CustomDialogBoxState createState() => _CustomDialogBoxState(); } class _CustomDialogBoxState extends State<CustomDialogBox> { @override Widget build(BuildContext context) { return Dialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(Constants.padding), ), elevation: 0, backgroundColor: Colors.transparent, child: contentBox(context), ); } contentBox(context){ return Stack( children: <Widget>[ Container( padding: EdgeInsets.only(left: Constants.padding,top: Constants.avatarRadius + Constants.padding, right: Constants.padding,bottom: Constants.padding ), margin: EdgeInsets.only(top: Constants.avatarRadius), decoration: BoxDecoration( shape: BoxShape.rectangle, color: Colors.white, borderRadius: BorderRadius.circular(Constants.padding), boxShadow: [ BoxShadow(color: Colors.black,offset: Offset(0,10), blurRadius: 10 ), ] ), child: Column( mainAxisSize: MainAxisSize.min, children: <Widget>[ Text(widget.title,style: TextStyle(fontSize: 22,fontWeight: FontWeight.w600),), SizedBox(height: 15,), Text(widget.descriptions,style: TextStyle(fontSize: 14),textAlign: TextAlign.center,), SizedBox(height: 22,), Align( alignment: Alignment.bottomRight, child: FlatButton( onPressed: (){ Navigator.of(context).pop(); }, child: Text(widget.text,style: TextStyle(fontSize: 18),)), ), ], ), ), Positioned( left: Constants.padding, right: Constants.padding, child: CircleAvatar( backgroundColor: Colors.transparent, radius: Constants.avatarRadius, child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(Constants.avatarRadius)), child: Image.asset("assets/model.jpeg") ), ), ), ], ); } }