mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Added toast message component
This commit is contained in:
@@ -9,7 +9,6 @@ import 'package:immich_mobile/shared/services/backup.service.dart';
|
||||
import 'package:immich_mobile/shared/services/device_info.service.dart';
|
||||
import 'package:immich_mobile/shared/services/network.service.dart';
|
||||
import 'package:immich_mobile/shared/models/device_info.model.dart';
|
||||
import 'package:immich_mobile/utils/dio_http_interceptor.dart';
|
||||
|
||||
class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||
AuthenticationNotifier()
|
||||
@@ -45,8 +44,12 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||
Hive.box(userInfoBox).put(serverEndpointKey, serverEndpoint);
|
||||
}
|
||||
|
||||
bool isServerEndpointVerified = await _networkService.pingServer();
|
||||
if (!isServerEndpointVerified) {
|
||||
try {
|
||||
bool isServerEndpointVerified = await _networkService.pingServer();
|
||||
if (!isServerEndpointVerified) {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
||||
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
||||
|
||||
class LoginForm extends HookConsumerWidget {
|
||||
const LoginForm({Key? key}) : super(key: key);
|
||||
@@ -116,7 +117,10 @@ class LoginButton extends ConsumerWidget {
|
||||
if (isAuthenicated) {
|
||||
AutoRouter.of(context).pushNamed("/home-page");
|
||||
} else {
|
||||
debugPrint("BAD LOGIN TRY AGAIN - Show UI Here");
|
||||
ImmichToast.show(
|
||||
context: context,
|
||||
msg: "Error logging you in, check server url, emald and password!",
|
||||
toastType: ToastType.error);
|
||||
}
|
||||
},
|
||||
child: const Text("Login"));
|
||||
|
||||
69
mobile/lib/shared/ui/immich_toast.dart
Normal file
69
mobile/lib/shared/ui/immich_toast.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
enum ToastType { info, success, error }
|
||||
|
||||
class ImmichToast {
|
||||
static show({
|
||||
required BuildContext context,
|
||||
required String msg,
|
||||
ToastType toastType = ToastType.info,
|
||||
}) {
|
||||
FToast fToast;
|
||||
|
||||
fToast = FToast();
|
||||
fToast.init(context);
|
||||
|
||||
fToast.showToast(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5.0),
|
||||
color: Colors.grey[50],
|
||||
border: Border.all(
|
||||
color: Colors.black12,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
(toastType == ToastType.info)
|
||||
? Icon(
|
||||
Icons.info_outline_rounded,
|
||||
color: Theme.of(context).primaryColor,
|
||||
)
|
||||
: Container(),
|
||||
(toastType == ToastType.success)
|
||||
? const Icon(
|
||||
Icons.check,
|
||||
color: Color.fromARGB(255, 104, 248, 140),
|
||||
)
|
||||
: Container(),
|
||||
(toastType == ToastType.error)
|
||||
? const Icon(
|
||||
Icons.error_outline_rounded,
|
||||
color: Color.fromARGB(255, 240, 162, 156),
|
||||
)
|
||||
: Container(),
|
||||
const SizedBox(
|
||||
width: 12.0,
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
msg,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
gravity: ToastGravity.TOP,
|
||||
toastDuration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user