2022-02-05 01:20:23 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2022-02-05 01:20:23 +02:00
|
|
|
|
|
|
|
enum ToastType { info, success, error }
|
|
|
|
|
|
|
|
class ImmichToast {
|
|
|
|
static show({
|
|
|
|
required BuildContext context,
|
|
|
|
required String msg,
|
|
|
|
ToastType toastType = ToastType.info,
|
2022-04-02 19:31:53 +02:00
|
|
|
ToastGravity gravity = ToastGravity.TOP,
|
2022-11-20 19:43:10 +02:00
|
|
|
int durationInSecond = 3,
|
2022-02-05 01:20:23 +02:00
|
|
|
}) {
|
2022-06-23 06:14:14 +02:00
|
|
|
final fToast = FToast();
|
2022-02-05 01:20:23 +02:00
|
|
|
fToast.init(context);
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
Color getColor(ToastType type, BuildContext context) {
|
2022-04-02 19:31:53 +02:00
|
|
|
switch (type) {
|
|
|
|
case ToastType.info:
|
2023-11-09 18:19:53 +02:00
|
|
|
return context.primaryColor;
|
2022-04-02 19:31:53 +02:00
|
|
|
case ToastType.success:
|
|
|
|
return const Color.fromARGB(255, 78, 140, 124);
|
|
|
|
case ToastType.error:
|
|
|
|
return const Color.fromARGB(255, 220, 48, 85);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 14:13:14 +02:00
|
|
|
Icon getIcon(ToastType type) {
|
2022-06-23 06:14:14 +02:00
|
|
|
switch (type) {
|
|
|
|
case ToastType.info:
|
|
|
|
return Icon(
|
|
|
|
Icons.info_outline_rounded,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2022-06-23 06:14:14 +02:00
|
|
|
);
|
|
|
|
case ToastType.success:
|
|
|
|
return const Icon(
|
|
|
|
Icons.check_circle_rounded,
|
|
|
|
color: Color.fromARGB(255, 78, 140, 124),
|
|
|
|
);
|
|
|
|
case ToastType.error:
|
|
|
|
return const Icon(
|
|
|
|
Icons.error_outline_rounded,
|
|
|
|
color: Color.fromARGB(255, 240, 162, 156),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 01:20:23 +02:00
|
|
|
fToast.showToast(
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.isDarkTheme ? Colors.grey[900] : Colors.grey[50],
|
2022-02-05 01:20:23 +02:00
|
|
|
border: Border.all(
|
|
|
|
color: Colors.black12,
|
|
|
|
width: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2022-11-21 14:13:14 +02:00
|
|
|
getIcon(toastType),
|
2022-02-05 01:20:23 +02:00
|
|
|
const SizedBox(
|
|
|
|
width: 12.0,
|
|
|
|
),
|
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
msg,
|
|
|
|
style: TextStyle(
|
2022-11-21 14:13:14 +02:00
|
|
|
color: getColor(toastType, context),
|
2022-02-05 01:20:23 +02:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-04-02 19:31:53 +02:00
|
|
|
gravity: gravity,
|
2022-11-20 19:43:10 +02:00
|
|
|
toastDuration: Duration(seconds: durationInSecond),
|
2022-02-05 01:20:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|