50 lines
1.4 KiB
Dart
50 lines
1.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
Future<T> showMobilePopup<T>({
|
|
@required BuildContext context,
|
|
bool barrierDismissible = true,
|
|
bool mobilePush = false,
|
|
WidgetBuilder builder,
|
|
}) {
|
|
if (mobilePush && (Platform.isIOS || Platform.isAndroid)) {
|
|
return Navigator.of(context).push<T>(
|
|
MaterialPageRoute(builder: builder),
|
|
);
|
|
}
|
|
|
|
assert(debugCheckHasMaterialLocalizations(context));
|
|
|
|
final ThemeData theme = Theme.of(context, shadowThemeOnly: true);
|
|
return showGeneralDialog(
|
|
context: context,
|
|
pageBuilder: (BuildContext buildContext, Animation<double> animation,
|
|
Animation<double> secondaryAnimation) {
|
|
final Widget pageChild = Builder(builder: builder);
|
|
return Builder(builder: (BuildContext context) {
|
|
return Theme(data: theme, child: pageChild);
|
|
});
|
|
},
|
|
barrierDismissible: barrierDismissible,
|
|
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
|
barrierColor: Colors.black54,
|
|
transitionDuration: const Duration(milliseconds: 150),
|
|
transitionBuilder: _buildMaterialDialogTransitions,
|
|
);
|
|
}
|
|
|
|
Widget _buildMaterialDialogTransitions(
|
|
BuildContext context,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
Widget child) {
|
|
return FadeTransition(
|
|
opacity: CurvedAnimation(
|
|
parent: animation,
|
|
curve: Curves.easeOut,
|
|
),
|
|
child: child,
|
|
);
|
|
}
|