Skip to content

Commit

Permalink
Use toast notification instead of snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
doraemonkeys committed Jul 8, 2023
1 parent 2f60768 commit e75ec7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
52 changes: 23 additions & 29 deletions flutter/clipboard/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:intl/intl.dart';
import 'package:dio/dio.dart';
import 'package:dio_http2_adapter/dio_http2_adapter.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:flutter_toastr/flutter_toastr.dart';

import 'web.dart';

Expand Down Expand Up @@ -646,6 +647,7 @@ class _HomePageState extends State<HomePage> {
),
onTap: () async {
var exited = false;
String msg = '';
// Show loading spinner
var dialog = showDialog(
context: context,
Expand All @@ -660,50 +662,40 @@ class _HomePageState extends State<HomePage> {

if (serverConfig.action == 'copy') {
try {
var msg = await _doCopyAction(serverConfig);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(msg)),
);
}
msg = await _doCopyAction(serverConfig);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
msg = e.toString();
}
} else if (serverConfig.action == 'paste' &&
serverConfig.pasteType == 'text') {
try {
await _doPasteTextAction(serverConfig);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('操作成功')),
);
}
msg = '操作成功';
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
msg = e.toString();
}
} else if (serverConfig.action == 'paste' &&
serverConfig.pasteType == 'file') {
try {
await _doPasteFileAction(serverConfig);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('操作成功')),
);
}
msg = '操作成功';
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
msg = e.toString();
}
}
if (context.mounted && !exited) {
// Hide loading spinner
Navigator.of(context).pop();
}
// if (context.mounted) {
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(content: Text(msg)),
// );
// }
if (context.mounted) {
FlutterToastr.show(msg, context,
duration: 3, position: FlutterToastr.bottom);
}
},
onLongPress: () {
// 长按弹出删除
Expand Down Expand Up @@ -929,10 +921,11 @@ class _HomePageState extends State<HomePage> {
final content = await response.transform(utf8.decoder).join();
await Clipboard.setData(ClipboardData(text: content));
//返回 复制成功
String successPrefix = '复制成功: \n';
if (content.length > 40) {
return '复制成功: ${content.substring(0, 40)}...';
return '$successPrefix${content.substring(0, 40)}...';
}
return '复制成功: $content';
return '$successPrefix$content';
}
if (dataType == 'clip-image') {
final imageName =
Expand Down Expand Up @@ -1008,10 +1001,11 @@ class _HomePageState extends State<HomePage> {
await Clipboard.setData(ClipboardData(text: utf8.decode(contentUint8List)));
var content = utf8.decode(contentUint8List);
//返回 复制成功
String successPrefix = '复制成功: \n';
if (content.length > 40) {
return '复制成功: ${content.substring(0, 40)}...';
return '$successPrefix${content.substring(0, 40)}...';
} else {
return '复制成功: $content';
return '$successPrefix$content';
}
}

Expand Down
3 changes: 2 additions & 1 deletion flutter/clipboard/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.4.4
version: 0.4.5

environment:
sdk: ">=3.0.3 <4.0.0"
Expand Down Expand Up @@ -52,6 +52,7 @@ dependencies:
git:
url: https://github.com/abhi16180/flutter_file_picker.git
ref: master
flutter_toastr: ^1.0.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit e75ec7a

Please sign in to comment.