refactor: replace snackbars by toasts
This commit is contained in:
@@ -4,9 +4,11 @@ import 'package:file_transfer/models/file_metadata.dart';
|
||||
import 'package:file_transfer/models/shared_file.dart';
|
||||
import 'package:file_saver/file_saver.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:toastification/toastification.dart';
|
||||
|
||||
class FileShareController extends GetxController {
|
||||
final _isLoading = false.obs;
|
||||
@@ -132,16 +134,20 @@ class FileShareController extends GetxController {
|
||||
customMimeType: mimeType,
|
||||
);
|
||||
|
||||
Get.snackbar(
|
||||
'Success',
|
||||
'File saved successfully',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
toastification.show(
|
||||
type: ToastificationType.success,
|
||||
style: ToastificationStyle.flatColored,
|
||||
title: const Text('File saved'),
|
||||
autoCloseDuration: const Duration(seconds: 2),
|
||||
alignment: Alignment.bottomCenter,
|
||||
);
|
||||
} catch (e) {
|
||||
Get.snackbar(
|
||||
'Error',
|
||||
'Failed to save file: $e',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
toastification.show(
|
||||
type: ToastificationType.error,
|
||||
style: ToastificationStyle.flatColored,
|
||||
title: Text('Failed to save: $e'),
|
||||
autoCloseDuration: const Duration(seconds: 3),
|
||||
alignment: Alignment.bottomCenter,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import 'package:file_transfer/models/shared_file.dart';
|
||||
import 'package:file_transfer/routes.dart';
|
||||
import 'package:file_transfer/utils/platform_helper.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_dropzone/flutter_dropzone.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
import 'package:toastification/toastification.dart';
|
||||
|
||||
class HomePageController extends GetxController {
|
||||
final _sharedFile = Rxn<SharedFile>();
|
||||
@@ -24,6 +26,19 @@ class HomePageController extends GetxController {
|
||||
bool get isDragging => _isDragging.value;
|
||||
bool get isWeb => kIsWeb;
|
||||
|
||||
void _showToast(
|
||||
String message, {
|
||||
ToastificationType type = ToastificationType.info,
|
||||
}) {
|
||||
toastification.show(
|
||||
type: type,
|
||||
style: ToastificationStyle.flatColored,
|
||||
title: Text(message),
|
||||
autoCloseDuration: const Duration(seconds: 2),
|
||||
alignment: Alignment.bottomCenter,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> handleDroppedFile(dynamic file) async {
|
||||
_isDragging.value = false;
|
||||
_isUploading.value = true;
|
||||
@@ -117,12 +132,7 @@ class HomePageController extends GetxController {
|
||||
|
||||
void copyToClipboard(String text, String label) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
Get.snackbar(
|
||||
'Copied',
|
||||
'$label copied to clipboard',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
_showToast('$label copied to clipboard');
|
||||
}
|
||||
|
||||
void copyShareLink() {
|
||||
@@ -144,10 +154,9 @@ class HomePageController extends GetxController {
|
||||
final link = clipboardData?.text;
|
||||
|
||||
if (link == null || link.isEmpty) {
|
||||
Get.snackbar(
|
||||
'No Link',
|
||||
_showToast(
|
||||
'No link found in clipboard',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
type: ToastificationType.warning,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -172,10 +181,6 @@ class HomePageController extends GetxController {
|
||||
// Invalid URL
|
||||
}
|
||||
|
||||
Get.snackbar(
|
||||
'Invalid Link',
|
||||
'Please copy a valid share link',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
);
|
||||
_showToast('Invalid share link format', type: ToastificationType.error);
|
||||
}
|
||||
}
|
||||
|
||||
+23
-20
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ndk/ndk.dart';
|
||||
import 'package:ndk_flutter/ndk_flutter.dart';
|
||||
import 'package:toastification/toastification.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -29,26 +30,28 @@ class MainApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetMaterialApp(
|
||||
title: 'File Transfer',
|
||||
theme: ThemeData.light(),
|
||||
darkTheme: ThemeData.dark(),
|
||||
getPages: [
|
||||
GetPage(
|
||||
name: AppRoutes.home,
|
||||
page: () => const HomePage(),
|
||||
binding: BindingsBuilder(() {
|
||||
Get.put(HomePageController());
|
||||
}),
|
||||
),
|
||||
GetPage(
|
||||
name: AppRoutes.fileShare,
|
||||
page: () => const FileSharePage(),
|
||||
binding: BindingsBuilder(() {
|
||||
Get.put(FileShareController());
|
||||
}),
|
||||
),
|
||||
],
|
||||
return ToastificationWrapper(
|
||||
child: GetMaterialApp(
|
||||
title: 'File Transfer',
|
||||
theme: ThemeData.light(),
|
||||
darkTheme: ThemeData.dark(),
|
||||
getPages: [
|
||||
GetPage(
|
||||
name: AppRoutes.home,
|
||||
page: () => const HomePage(),
|
||||
binding: BindingsBuilder(() {
|
||||
Get.put(HomePageController());
|
||||
}),
|
||||
),
|
||||
GetPage(
|
||||
name: AppRoutes.fileShare,
|
||||
page: () => const FileSharePage(),
|
||||
binding: BindingsBuilder(() {
|
||||
Get.put(FileShareController());
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -683,7 +683,7 @@ packages:
|
||||
source: hosted
|
||||
version: "0.7.9"
|
||||
toastification:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: toastification
|
||||
sha256: "69db2bff425b484007409650d8bcd5ed1ce2e9666293ece74dcd917dacf23112"
|
||||
|
||||
@@ -21,6 +21,7 @@ dependencies:
|
||||
ndk_flutter: ^0.0.2-dev.13
|
||||
nip49: ^1.1.2
|
||||
path: ^1.9.1
|
||||
toastification: ^3.0.3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user