SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6.   // This widget is the root of your application.
  7.   @override
  8.   Widget build(BuildContext context) {
  9.     return MaterialApp(
  10.       title: 'Flutter Demo',
  11.       theme: ThemeData(
  12.         // This is the theme of your application.
  13.         //
  14.         // Try running your application with "flutter run". You'll see the
  15.         // application has a blue toolbar. Then, without quitting the app, try
  16.         // changing the primarySwatch below to Colors.green and then invoke
  17.         // "hot reload" (press "r" in the console where you ran "flutter run",
  18.         // or simply save your changes to "hot reload" in a Flutter IDE).
  19.         // Notice that the counter didn't reset back to zero; the application
  20.         // is not restarted.
  21.         primarySwatch: Colors.blue,
  22.       ),
  23.       home: MyHomePage(),
  24.     );
  25.   }
  26. }
  27.  
  28. class MyHomePage extends StatelessWidget {
  29.   @override
  30.   Widget build(BuildContext context) {
  31.     return Scaffold(
  32.       body: Center(
  33.         child: RaisedButton(
  34.           color: Color(0xFF1BC0C5),
  35.           shape:
  36.               RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
  37.           child: SizedBox(
  38.             width: 100,
  39.             height: 50,
  40.             child: Center(
  41.               child: Text("Click Me"),
  42.             ),
  43.           ),
  44.           onPressed: () {
  45.             showDialog(
  46.               context: context,
  47.               builder: (BuildContext context) => CustomDialog(
  48.                 title: "Success",
  49.                 description:
  50.                     "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
  51.                 buttonText: "Okay",
  52.               ),
  53.             );
  54.           },
  55.         ),
  56.       ),
  57.     );
  58.   }
  59. }
  60.  
  61. class CustomDialog extends StatelessWidget {
  62.   final String title, description, buttonText;
  63.   final Image image;
  64.  
  65.   CustomDialog({
  66.     @required this.title,
  67.     @required this.description,
  68.     @required this.buttonText,
  69.     this.image,
  70.   });
  71.  
  72.   @override
  73.   Widget build(BuildContext context) {
  74.     return Dialog(
  75.       shape: RoundedRectangleBorder(
  76.         borderRadius: BorderRadius.circular(16),
  77.       ),
  78.       elevation: 0.0,
  79.       backgroundColor: Colors.transparent,
  80.       child: dialogContent(context),
  81.     );
  82.   }
  83.  
  84.   dialogContent(BuildContext context) {
  85.     return Stack(
  86.       children: <Widget>[
  87.         Container(
  88.           padding: EdgeInsets.only(
  89.             top: 100,
  90.             bottom: 16,
  91.             left: 16,
  92.             right: 16,
  93.           ),
  94.           margin: EdgeInsets.only(top: 16),
  95.           decoration: new BoxDecoration(
  96.             color: Colors.white,
  97.             shape: BoxShape.rectangle,
  98.             borderRadius: BorderRadius.circular(16),
  99.             boxShadow: [
  100.               BoxShadow(
  101.                 color: Colors.black26,
  102.                 blurRadius: 10.0,
  103.                 offset: const Offset(0.0, 10.0),
  104.               ),
  105.             ],
  106.           ),
  107.           child: Column(
  108.             mainAxisSize: MainAxisSize.min, // To make the card compact
  109.             children: <Widget>[
  110.               Text(
  111.                 title,
  112.                 style: TextStyle(
  113.                   fontSize: 24.0,
  114.                   fontWeight: FontWeight.w700,
  115.                 ),
  116.               ),
  117.               SizedBox(height: 16.0),
  118.               Text(
  119.                 description,
  120.                 textAlign: TextAlign.center,
  121.                 style: TextStyle(
  122.                   fontSize: 16.0,
  123.                 ),
  124.               ),
  125.               SizedBox(height: 24.0),
  126.               Align(
  127.                 alignment: Alignment.bottomRight,
  128.                 child: FlatButton(
  129.                   onPressed: () {
  130.                     Navigator.of(context).pop(); // To close the dialog
  131.                   },
  132.                   child: Text(buttonText),
  133.                 ),
  134.               ),
  135.             ],
  136.           ),
  137.         ),
  138.         Positioned(
  139.           top: 0,
  140.           left: 16,
  141.           right: 16,
  142.           child: CircleAvatar(
  143.             backgroundColor: Colors.blueAccent,
  144.             radius: 50,
  145.             backgroundImage: AssetImage('assets/XLpr.gif'),
  146.           ),
  147.         ),
  148.       ],
  149.     );
  150.   }
  151. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top