animated_dailog 0.0.1
animated_dailog: ^0.0.1 copied to clipboard
Flutter Animated Dailog.
example/main.dart
// ignore_for_file: prefer_const_constructors
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Animated Dailog',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Animated Dailog'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Animated Dailog'),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
showPlatformDialog(
builder: (context) => AnimatedDailog(), context: context);
},
tooltip: 'Open Dialog',
child: const Icon(Icons.add),
),
);
}
}
Future<T?> showPlatformDialog<T>({
required BuildContext context,
required WidgetBuilder builder,
androidBarrierDismissible = false,
useRootNavigator = true,
}) {
return showDialog(context: context, builder: builder);
}
class AnimatedDailog extends StatefulWidget {
final double? height;
final double? width;
final String? title;
final Widget? content;
final List<Widget>? actions;
final bool centerTitle;
final Color? color;
final double? borderRadius;
const AnimatedDailog({
this.height,
this.width,
this.title,
this.content,
this.actions,
this.centerTitle = false,
this.color = Colors.white,
this.borderRadius = 20,
Key? key,
}) : super(key: key);
@override
State<AnimatedDailog> createState() => _AnimatedDailogState();
}
class _AnimatedDailogState extends State<AnimatedDailog> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Center(
child: Card(
elevation: 2,
color: widget.color,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(widget.borderRadius!),
),
child: AnimatedContainer(
height: widget.height ?? size.height / 2,
width: widget.width ?? size.width * 0.85,
decoration: BoxDecoration(
color: widget.color,
borderRadius: BorderRadius.circular(widget.borderRadius!)),
duration: Duration(seconds: 1),
child: Column(children: [
const SizedBox(
height: 10,
),
Text(
widget.title ?? "Animated Dialog",
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 17),
),
const SizedBox(
height: 4,
),
Divider(
indent: 20,
endIndent: 20,
thickness: 1,
color: Colors.grey.shade200,
),
Expanded(
child: widget.content ??
const Center(
// ignore: unnecessary_const
child: const Text(
"Animated Dialog\nContent Here",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 17),
),
),
),
const SizedBox(
height: 2,
),
Divider(
indent: 20,
endIndent: 20,
thickness: 1,
height: 0,
color: Colors.grey.shade200,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: widget.actions ??
[
OutlinedButton(
style: ButtonStyle(
side: MaterialStateProperty.all(
const BorderSide(
width: 2,
),
),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(10)))),
onPressed: () {
Navigator.of(context).pop();
},
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: Text(
"OK",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 17),
),
),
),
]
// children: [
// SizedBox(
// width: 12,
// ),
// ],
),
),
const SizedBox(
height: 5,
),
]),
),
),
);
}
}