Last active
March 1, 2024 03:00
-
-
Save kumamotone/b9b0a3d20b12a29596d736941c9695b7 to your computer and use it in GitHub Desktop.
showCommonDialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Dialog Demo', | |
theme: ThemeData( | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: const CommonDialogCatalogScreen(), | |
); | |
} | |
} | |
class CommonDialogCatalogScreen extends StatelessWidget { | |
const CommonDialogCatalogScreen({super.key}); | |
Future<void> showCustomContentDialog(BuildContext context) async { | |
await showCommonDialog<void>( | |
context: context, | |
builder: (context) => const Padding( | |
padding: EdgeInsets.all(24), | |
child: Text('Custom Content'), | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('CustomContentDialog Demo'), | |
), | |
body: ListView( | |
padding: const EdgeInsets.all(8), | |
children: <Widget>[ | |
ElevatedButton( | |
onPressed: () => showCustomContentDialog(context), | |
child: const Text('Show Custom Content Dialog'), | |
), | |
], | |
), | |
); | |
} | |
} | |
Future<T?> showCommonDialog<T>({ | |
required BuildContext context, | |
required WidgetBuilder builder, | |
bool barrierDismissible = true, | |
Color? barrierColor, | |
bool useRootNavigator = true, | |
Color? backgroundColor, | |
Clip clipBehavior = Clip.none, | |
Alignment alignment = Alignment.center, | |
EdgeInsets? insetPadding, | |
double elevation = 0, | |
}) { | |
return showDialog<T>( | |
context: context, | |
barrierDismissible: barrierDismissible, | |
barrierColor: barrierColor, | |
useRootNavigator: useRootNavigator, | |
builder: (context) => Dialog( | |
backgroundColor: | |
backgroundColor ?? Theme.of(context).dialogBackgroundColor, | |
clipBehavior: clipBehavior, | |
insetPadding: insetPadding, | |
alignment: alignment, | |
elevation: elevation, | |
child: builder(context), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment