2022-08-26 08:11:35 +00:00
|
|
|
import 'package:another_flushbar/flushbar.dart';
|
|
|
|
import 'package:another_flushbar/flushbar_route.dart' as flushRoute;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-11-18 15:07:11 +00:00
|
|
|
export 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
Future<dynamic> showFloatingFlushBar({
|
|
|
|
required FlushBarType type,
|
|
|
|
required String message,
|
|
|
|
String? iconAsset,
|
|
|
|
required BuildContext context,
|
|
|
|
Duration? duration = const Duration(milliseconds: 1500),
|
|
|
|
FlushbarPosition flushbarPosition = FlushbarPosition.TOP,
|
|
|
|
VoidCallback? onTap,
|
|
|
|
}) {
|
|
|
|
Color bg;
|
|
|
|
Color fg;
|
|
|
|
switch (type) {
|
|
|
|
case FlushBarType.success:
|
2022-09-22 23:48:50 +00:00
|
|
|
fg = Theme.of(context).extension<StackColors>()!.snackBarTextSuccess;
|
|
|
|
bg = Theme.of(context).extension<StackColors>()!.snackBarBackSuccess;
|
2022-08-26 08:11:35 +00:00
|
|
|
break;
|
|
|
|
case FlushBarType.info:
|
2022-09-22 23:48:50 +00:00
|
|
|
fg = Theme.of(context).extension<StackColors>()!.snackBarTextInfo;
|
|
|
|
bg = Theme.of(context).extension<StackColors>()!.snackBarBackInfo;
|
2022-08-26 08:11:35 +00:00
|
|
|
break;
|
|
|
|
case FlushBarType.warning:
|
2022-09-22 23:48:50 +00:00
|
|
|
fg = Theme.of(context).extension<StackColors>()!.snackBarTextError;
|
|
|
|
bg = Theme.of(context).extension<StackColors>()!.snackBarBackError;
|
2022-08-26 08:11:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
final bar = Flushbar<dynamic>(
|
|
|
|
onTap: (_) {
|
|
|
|
onTap?.call();
|
|
|
|
},
|
|
|
|
icon: iconAsset != null
|
|
|
|
? SvgPicture.asset(
|
|
|
|
iconAsset,
|
|
|
|
height: 16,
|
|
|
|
width: 16,
|
|
|
|
color: fg,
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
message: message,
|
|
|
|
messageColor: fg,
|
|
|
|
flushbarPosition: flushbarPosition,
|
|
|
|
backgroundColor: bg,
|
|
|
|
duration: duration,
|
|
|
|
flushbarStyle: FlushbarStyle.FLOATING,
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
|
|
|
),
|
|
|
|
margin: const EdgeInsets.all(20),
|
2022-09-15 19:48:28 +00:00
|
|
|
maxWidth: 550,
|
2022-08-26 08:11:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
final _route = flushRoute.showFlushbar<dynamic>(
|
|
|
|
context: context,
|
|
|
|
flushbar: bar,
|
|
|
|
);
|
|
|
|
|
|
|
|
return Navigator.of(context, rootNavigator: true).push(_route);
|
|
|
|
}
|