update dialog,use flutter_smart_dialog
This commit is contained in:
parent
24bc515061
commit
85c3dbdf7f
@ -582,7 +582,6 @@ class MainService : Service() {
|
|||||||
username: String,
|
username: String,
|
||||||
peerId: String
|
peerId: String
|
||||||
) {
|
) {
|
||||||
cancelNotification(clientID)
|
|
||||||
val notification = notificationBuilder
|
val notification = notificationBuilder
|
||||||
.setOngoing(false)
|
.setOngoing(false)
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
|
149
lib/common.dart
149
lib/common.dart
@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
|
||||||
|
import 'models/model.dart';
|
||||||
|
|
||||||
final globalKey = GlobalKey<NavigatorState>();
|
final globalKey = GlobalKey<NavigatorState>();
|
||||||
final navigationBarKey = GlobalKey();
|
final navigationBarKey = GlobalKey();
|
||||||
@ -42,37 +44,40 @@ final ButtonStyle flatButtonStyle = TextButton.styleFrom(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
void showToast(String text) {
|
void showToast(String text,{Duration? duration}) {
|
||||||
EasyLoading.showToast(Translator.call(text),
|
SmartDialog.showToast(text,displayTime: duration);
|
||||||
maskType: EasyLoadingMaskType.black);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void showLoading(String text) {
|
void showLoading(String text, {bool clickMaskDismiss = false}) {
|
||||||
DialogManager.reset();
|
SmartDialog.dismiss();
|
||||||
EasyLoading.dismiss();
|
SmartDialog.showLoading(
|
||||||
EasyLoading.show(
|
clickMaskDismiss: false,
|
||||||
indicator: Container(
|
builder: (context) {
|
||||||
constraints: BoxConstraints(maxWidth: 240),
|
return Container(
|
||||||
child:
|
color: MyTheme.white,
|
||||||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
constraints: BoxConstraints(maxWidth: 240),
|
||||||
SizedBox(height: 30),
|
child: Column(
|
||||||
Center(child: CircularProgressIndicator()),
|
mainAxisSize: MainAxisSize.min,
|
||||||
SizedBox(height: 20),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Center(
|
children: [
|
||||||
child: Text(Translator.call(text),
|
SizedBox(height: 30),
|
||||||
style: TextStyle(fontSize: 15))),
|
Center(child: CircularProgressIndicator()),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Center(
|
Center(
|
||||||
child: TextButton(
|
child: Text(Translator.call(text),
|
||||||
style: flatButtonStyle,
|
style: TextStyle(fontSize: 15))),
|
||||||
onPressed: () {
|
SizedBox(height: 20),
|
||||||
EasyLoading.dismiss();
|
Center(
|
||||||
backToHome();
|
child: TextButton(
|
||||||
},
|
style: flatButtonStyle,
|
||||||
child: Text(Translator.call('Cancel'),
|
onPressed: () {
|
||||||
style: TextStyle(color: MyTheme.accent))))
|
SmartDialog.dismiss();
|
||||||
])),
|
backToHome();
|
||||||
maskType: EasyLoadingMaskType.black);
|
},
|
||||||
|
child: Text(Translator.call('Cancel'),
|
||||||
|
style: TextStyle(color: MyTheme.accent))))
|
||||||
|
]));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
backToHome() {
|
backToHome() {
|
||||||
@ -80,40 +85,36 @@ backToHome() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef DialogBuilder = CustomAlertDialog Function(
|
typedef DialogBuilder = CustomAlertDialog Function(
|
||||||
StateSetter setState, Function([dynamic]) close);
|
StateSetter setState, void Function([dynamic]) close);
|
||||||
|
|
||||||
class DialogManager {
|
class DialogManager {
|
||||||
static BuildContext? _dialogContext;
|
static int _tag = 0;
|
||||||
|
|
||||||
static void reset([result]) {
|
static dismissByTag(String tag, [result]) {
|
||||||
if (_dialogContext != null) {
|
SmartDialog.dismiss(tag: tag, result: result);
|
||||||
Navigator.pop(_dialogContext!, result);
|
|
||||||
}
|
|
||||||
_dialogContext = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void register(BuildContext dialogContext) {
|
|
||||||
_dialogContext = dialogContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void drop() {
|
|
||||||
_dialogContext = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<T?> show<T>(DialogBuilder builder,
|
static Future<T?> show<T>(DialogBuilder builder,
|
||||||
{bool barrierDismissible = false}) async {
|
{bool barrierDismissible = false,
|
||||||
if (globalKey.currentContext == null) return null;
|
String? tag,
|
||||||
EasyLoading.dismiss();
|
bool useAnimation = true}) async {
|
||||||
DialogManager.reset();
|
final t;
|
||||||
final res = await showDialog<T>(
|
if (tag != null) {
|
||||||
context: globalKey.currentContext!,
|
t = tag;
|
||||||
barrierDismissible: barrierDismissible,
|
} else {
|
||||||
builder: (context) {
|
_tag += 1;
|
||||||
DialogManager.register(context);
|
t = _tag.toString();
|
||||||
return StatefulBuilder(
|
}
|
||||||
builder: (_, setState) => builder(setState, DialogManager.reset));
|
SmartDialog.dismiss(status: SmartStatus.allToast);
|
||||||
});
|
SmartDialog.dismiss(status: SmartStatus.loading);
|
||||||
DialogManager.drop();
|
final close = ([res]) {
|
||||||
|
SmartDialog.dismiss(tag: t, result: res);
|
||||||
|
};
|
||||||
|
final res = await SmartDialog.show<T>(
|
||||||
|
tag: t,
|
||||||
|
useAnimation: useAnimation,
|
||||||
|
builder: (_) => StatefulBuilder(
|
||||||
|
builder: (_, setState) => builder(setState, close)));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +148,6 @@ class CustomAlertDialog extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EasyLoading
|
|
||||||
void msgBox(String type, String title, String text, {bool? hasCancel}) {
|
void msgBox(String type, String title, String text, {bool? hasCancel}) {
|
||||||
var wrap = (String text, void Function() onPressed) => ButtonTheme(
|
var wrap = (String text, void Function() onPressed) => ButtonTheme(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||||
@ -162,12 +162,10 @@ void msgBox(String type, String title, String text, {bool? hasCancel}) {
|
|||||||
child: Text(Translator.call(text),
|
child: Text(Translator.call(text),
|
||||||
style: TextStyle(color: MyTheme.accent))));
|
style: TextStyle(color: MyTheme.accent))));
|
||||||
|
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
DialogManager.reset();
|
|
||||||
final buttons = [
|
final buttons = [
|
||||||
Expanded(child: Container()),
|
|
||||||
wrap(Translator.call('OK'), () {
|
wrap(Translator.call('OK'), () {
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
backToHome();
|
backToHome();
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@ -176,28 +174,15 @@ void msgBox(String type, String title, String text, {bool? hasCancel}) {
|
|||||||
}
|
}
|
||||||
if (hasCancel) {
|
if (hasCancel) {
|
||||||
buttons.insert(
|
buttons.insert(
|
||||||
1,
|
0,
|
||||||
wrap(Translator.call('Cancel'), () {
|
wrap(Translator.call('Cancel'), () {
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
EasyLoading.show(
|
DialogManager.show((setState, close) => CustomAlertDialog(
|
||||||
status: "",
|
title: Text(translate(title), style: TextStyle(fontSize: 21)),
|
||||||
maskType: EasyLoadingMaskType.black,
|
content: Text(Translator.call(text), style: TextStyle(fontSize: 15)),
|
||||||
indicator: Container(
|
actions: buttons));
|
||||||
constraints: BoxConstraints(maxWidth: 300),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(Translator.call(title), style: TextStyle(fontSize: 21)),
|
|
||||||
SizedBox(height: 20),
|
|
||||||
Text(Translator.call(text), style: TextStyle(fontSize: 15)),
|
|
||||||
SizedBox(height: 20),
|
|
||||||
Row(
|
|
||||||
children: buttons,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Color str2color(String str, [alpha = 0xFF]) {
|
Color str2color(String str, [alpha = 0xFF]) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:firebase_analytics/firebase_analytics.dart';
|
import 'package:firebase_analytics/firebase_analytics.dart';
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
@ -16,7 +16,7 @@ Future<Null> main() async {
|
|||||||
await a;
|
await a;
|
||||||
await b;
|
await b;
|
||||||
refreshCurrentUser();
|
refreshCurrentUser();
|
||||||
EasyLoading.instance.loadingStyle = EasyLoadingStyle.light;
|
// EasyLoading.instance.loadingStyle = EasyLoadingStyle.light;
|
||||||
toAndroidChannelInit();
|
toAndroidChannelInit();
|
||||||
runApp(App());
|
runApp(App());
|
||||||
}
|
}
|
||||||
@ -43,14 +43,15 @@ class App extends StatelessWidget {
|
|||||||
home: !isAndroid ? WebHomePage() : HomePage(),
|
home: !isAndroid ? WebHomePage() : HomePage(),
|
||||||
navigatorObservers: [
|
navigatorObservers: [
|
||||||
FirebaseAnalyticsObserver(analytics: analytics),
|
FirebaseAnalyticsObserver(analytics: analytics),
|
||||||
|
FlutterSmartDialog.observer
|
||||||
],
|
],
|
||||||
builder: isAndroid
|
builder: isAndroid
|
||||||
? (_, child) {
|
? (_, child) {
|
||||||
return AccessibilityListener(
|
return AccessibilityListener(
|
||||||
child: FlutterEasyLoading(child: child),
|
child: FlutterSmartDialog(child: child),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
: EasyLoading.init(),
|
: FlutterSmartDialog.init(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
||||||
import 'package:flutter_hbb/common.dart';
|
import 'package:flutter_hbb/common.dart';
|
||||||
import 'package:flutter_hbb/pages/file_manager_page.dart';
|
import 'package:flutter_hbb/pages/file_manager_page.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:path/path.dart' as Path;
|
import 'package:path/path.dart' as Path;
|
||||||
|
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
@ -176,8 +176,7 @@ class FileModel extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClose() {
|
onClose() {
|
||||||
DialogManager.reset();
|
SmartDialog.dismiss();
|
||||||
EasyLoading.dismiss();
|
|
||||||
|
|
||||||
// save config
|
// save config
|
||||||
Map<String, String> msg = Map();
|
Map<String, String> msg = Map();
|
||||||
@ -289,7 +288,7 @@ class FileModel extends ChangeNotifier {
|
|||||||
fd.path = item.path;
|
fd.path = item.path;
|
||||||
}
|
}
|
||||||
fd.format(isWindows);
|
fd.format(isWindows);
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
if (fd.entries.isEmpty) {
|
if (fd.entries.isEmpty) {
|
||||||
final confirm = await showRemoveDialog(
|
final confirm = await showRemoveDialog(
|
||||||
translate(
|
translate(
|
||||||
@ -346,49 +345,50 @@ class FileModel extends ChangeNotifier {
|
|||||||
|
|
||||||
Future<bool?> showRemoveDialog(
|
Future<bool?> showRemoveDialog(
|
||||||
String title, String content, bool showCheckbox) async {
|
String title, String content, bool showCheckbox) async {
|
||||||
return await DialogManager.show<bool>((setState, Function(bool v) close) =>
|
return await DialogManager.show<bool>(
|
||||||
CustomAlertDialog(
|
(setState, Function(bool v) close) => CustomAlertDialog(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.warning, color: Colors.red),
|
Icon(Icons.warning, color: Colors.red),
|
||||||
SizedBox(width: 20),
|
SizedBox(width: 20),
|
||||||
Text(title)
|
Text(title)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
content: Column(
|
content: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(content),
|
Text(content),
|
||||||
SizedBox(height: 5),
|
SizedBox(height: 5),
|
||||||
Text(translate("This is irreversible!"),
|
Text(translate("This is irreversible!"),
|
||||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
showCheckbox
|
showCheckbox
|
||||||
? CheckboxListTile(
|
? CheckboxListTile(
|
||||||
contentPadding: const EdgeInsets.all(0),
|
contentPadding: const EdgeInsets.all(0),
|
||||||
dense: true,
|
dense: true,
|
||||||
controlAffinity: ListTileControlAffinity.leading,
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
title: Text(
|
title: Text(
|
||||||
translate("Do this for all conflicts"),
|
translate("Do this for all conflicts"),
|
||||||
),
|
),
|
||||||
value: removeCheckboxRemember,
|
value: removeCheckboxRemember,
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
if (v == null) return;
|
if (v == null) return;
|
||||||
setState(() => removeCheckboxRemember = v);
|
setState(() => removeCheckboxRemember = v);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
: SizedBox.shrink()
|
: SizedBox.shrink()
|
||||||
|
]),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
style: flatButtonStyle,
|
||||||
|
onPressed: () => close(false),
|
||||||
|
child: Text(translate("Cancel"))),
|
||||||
|
TextButton(
|
||||||
|
style: flatButtonStyle,
|
||||||
|
onPressed: () => close(true),
|
||||||
|
child: Text(translate("OK"))),
|
||||||
]),
|
]),
|
||||||
actions: [
|
useAnimation: false);
|
||||||
TextButton(
|
|
||||||
style: flatButtonStyle,
|
|
||||||
onPressed: () => close(false),
|
|
||||||
child: Text(translate("Cancel"))),
|
|
||||||
TextButton(
|
|
||||||
style: flatButtonStyle,
|
|
||||||
onPressed: () => close(true),
|
|
||||||
child: Text(translate("OK"))),
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendRemoveFile(String path, int fileNum, bool isLocal) {
|
sendRemoveFile(String path, int fileNum, bool isLocal) {
|
||||||
@ -526,7 +526,7 @@ class FileFetcher {
|
|||||||
final fd = FileDirectory.fromJson(jsonDecode(msg));
|
final fd = FileDirectory.fromJson(jsonDecode(msg));
|
||||||
if (fd.id > 0) {
|
if (fd.id > 0) {
|
||||||
// fd.id > 0 is result for read recursive
|
// fd.id > 0 is result for read recursive
|
||||||
// TODO later,will be better if every fetch use ID,so that there will only one task map for read and recursive read
|
// to-do later,will be better if every fetch use ID,so that there will only one task map for read and recursive read
|
||||||
tasks = readRecursiveTasks;
|
tasks = readRecursiveTasks;
|
||||||
final completer = tasks.remove(fd.id);
|
final completer = tasks.remove(fd.id);
|
||||||
completer?.complete(fd);
|
completer?.complete(fd);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
||||||
import 'package:flutter_hbb/models/chat_model.dart';
|
import 'package:flutter_hbb/models/chat_model.dart';
|
||||||
import 'package:flutter_hbb/models/file_model.dart';
|
import 'package:flutter_hbb/models/file_model.dart';
|
||||||
import 'package:flutter_hbb/models/server_model.dart';
|
import 'package:flutter_hbb/models/server_model.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
@ -159,7 +159,7 @@ class FfiModel with ChangeNotifier {
|
|||||||
if (rgba != null) {
|
if (rgba != null) {
|
||||||
if (_waitForImage) {
|
if (_waitForImage) {
|
||||||
_waitForImage = false;
|
_waitForImage = false;
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
}
|
}
|
||||||
_decoding = true;
|
_decoding = true;
|
||||||
final pid = FFI.id;
|
final pid = FFI.id;
|
||||||
@ -221,8 +221,7 @@ class FfiModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handlePeerInfo(Map<String, dynamic> evt) {
|
void handlePeerInfo(Map<String, dynamic> evt) {
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
DialogManager.reset();
|
|
||||||
_pi.version = evt['version'];
|
_pi.version = evt['version'];
|
||||||
_pi.username = evt['username'];
|
_pi.username = evt['username'];
|
||||||
_pi.hostname = evt['hostname'];
|
_pi.hostname = evt['hostname'];
|
||||||
@ -484,16 +483,11 @@ class CursorModel with ChangeNotifier {
|
|||||||
void updatePan(double dx, double dy, bool touchMode) {
|
void updatePan(double dx, double dy, bool touchMode) {
|
||||||
if (FFI.imageModel.image == null) return;
|
if (FFI.imageModel.image == null) return;
|
||||||
if (touchMode) {
|
if (touchMode) {
|
||||||
if (true) {
|
final scale = FFI.canvasModel.scale;
|
||||||
final scale = FFI.canvasModel.scale;
|
_x += dx / scale;
|
||||||
_x += dx / scale;
|
_y += dy / scale;
|
||||||
_y += dy / scale;
|
FFI.moveMouse(_x, _y);
|
||||||
FFI.moveMouse(_x, _y);
|
notifyListeners();
|
||||||
notifyListeners();
|
|
||||||
} else {
|
|
||||||
FFI.canvasModel.panX(dx);
|
|
||||||
FFI.canvasModel.panY(dy);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final scale = FFI.canvasModel.scale;
|
final scale = FFI.canvasModel.scale;
|
||||||
|
@ -6,6 +6,7 @@ import '../common.dart';
|
|||||||
import '../pages/server_page.dart';
|
import '../pages/server_page.dart';
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
|
|
||||||
|
const loginDialogTag = "LOGIN";
|
||||||
final _emptyIdShow = translate("Generating ...");
|
final _emptyIdShow = translate("Generating ...");
|
||||||
|
|
||||||
class ServerModel with ChangeNotifier {
|
class ServerModel with ChangeNotifier {
|
||||||
@ -306,70 +307,89 @@ class ServerModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loginRequest(Map<String, dynamic> evt) {
|
void loginRequest(Map<String, dynamic> evt) {
|
||||||
try {
|
try {
|
||||||
final client = Client.fromJson(jsonDecode(evt["client"]));
|
final client = Client.fromJson(jsonDecode(evt["client"]));
|
||||||
final Map<String, dynamic> response = Map();
|
if (_clients.containsKey(client.id)) {
|
||||||
response["id"] = client.id;
|
return;
|
||||||
DialogManager.show(
|
}
|
||||||
(setState, close) => CustomAlertDialog(
|
_clients[client.id] = client;
|
||||||
title: Row(
|
notifyListeners();
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
showLoginDialog(client);
|
||||||
children: [
|
|
||||||
Text(translate(client.isFileTransfer
|
|
||||||
? "File Connection"
|
|
||||||
: "Screen Connection")),
|
|
||||||
IconButton(onPressed: close, icon: Icon(Icons.close))
|
|
||||||
]),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(translate("Do you accept?")),
|
|
||||||
clientInfo(client),
|
|
||||||
Text(
|
|
||||||
translate("android_new_connection_tip"),
|
|
||||||
style: TextStyle(color: Colors.black54),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
child: Text(translate("Dismiss")),
|
|
||||||
onPressed: () {
|
|
||||||
response["res"] = false;
|
|
||||||
FFI.setByName("login_res", jsonEncode(response));
|
|
||||||
FFI.invokeMethod("cancel_notification", client.id);
|
|
||||||
close();
|
|
||||||
}),
|
|
||||||
ElevatedButton(
|
|
||||||
child: Text(translate("Accept")),
|
|
||||||
onPressed: () async {
|
|
||||||
response["res"] = true;
|
|
||||||
FFI.setByName("login_res", jsonEncode(response));
|
|
||||||
if (!client.isFileTransfer) {
|
|
||||||
FFI.invokeMethod("start_capture");
|
|
||||||
}
|
|
||||||
FFI.invokeMethod("cancel_notification", client.id);
|
|
||||||
_clients[client.id] = client;
|
|
||||||
notifyListeners();
|
|
||||||
close();
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
onWillPop: () async => true,
|
|
||||||
),
|
|
||||||
barrierDismissible: true);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint("loginRequest failed,error:$e");
|
debugPrint("Failed to call loginRequest,error:$e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void showLoginDialog(Client client) {
|
||||||
|
DialogManager.show(
|
||||||
|
(setState, close) => CustomAlertDialog(
|
||||||
|
title: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(translate(client.isFileTransfer
|
||||||
|
? "File Connection"
|
||||||
|
: "Screen Connection")),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
close();
|
||||||
|
},
|
||||||
|
icon: Icon(Icons.close))
|
||||||
|
]),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(translate("Do you accept?")),
|
||||||
|
clientInfo(client),
|
||||||
|
Text(
|
||||||
|
translate("android_new_connection_tip"),
|
||||||
|
style: TextStyle(color: Colors.black54),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: Text(translate("Dismiss")),
|
||||||
|
onPressed: () {
|
||||||
|
sendLoginResponse(client, false);
|
||||||
|
close();
|
||||||
|
}),
|
||||||
|
ElevatedButton(
|
||||||
|
child: Text(translate("Accept")),
|
||||||
|
onPressed: () {
|
||||||
|
sendLoginResponse(client, true);
|
||||||
|
close();
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
tag: getLoginDialogTag(client.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendLoginResponse(Client client, bool res) {
|
||||||
|
final Map<String, dynamic> response = Map();
|
||||||
|
response["id"] = client.id;
|
||||||
|
response["res"] = res;
|
||||||
|
if (res) {
|
||||||
|
FFI.setByName("login_res", jsonEncode(response));
|
||||||
|
if (!client.isFileTransfer) {
|
||||||
|
FFI.invokeMethod("start_capture");
|
||||||
|
}
|
||||||
|
FFI.invokeMethod("cancel_notification", client.id);
|
||||||
|
_clients[client.id]?.authorized = true;
|
||||||
|
notifyListeners();
|
||||||
|
} else {
|
||||||
|
FFI.setByName("login_res", jsonEncode(response));
|
||||||
|
FFI.invokeMethod("cancel_notification", client.id);
|
||||||
|
_clients.remove(client.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onClientAuthorized(Map<String, dynamic> evt) {
|
void onClientAuthorized(Map<String, dynamic> evt) {
|
||||||
try {
|
try {
|
||||||
final client = Client.fromJson(jsonDecode(evt['client']));
|
final client = Client.fromJson(jsonDecode(evt['client']));
|
||||||
// reset the login dialog, to-do,it will close any showing dialog
|
DialogManager.dismissByTag(getLoginDialogTag(client.id));
|
||||||
DialogManager.reset();
|
|
||||||
_clients[client.id] = client;
|
_clients[client.id] = client;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@ -380,9 +400,7 @@ class ServerModel with ChangeNotifier {
|
|||||||
final id = int.parse(evt['id'] as String);
|
final id = int.parse(evt['id'] as String);
|
||||||
if (_clients.containsKey(id)) {
|
if (_clients.containsKey(id)) {
|
||||||
_clients.remove(id);
|
_clients.remove(id);
|
||||||
} else {
|
DialogManager.dismissByTag(getLoginDialogTag(id));
|
||||||
// reset the login dialog, to-do,it will close any showing dialog
|
|
||||||
DialogManager.reset();
|
|
||||||
FFI.invokeMethod("cancel_notification", id);
|
FFI.invokeMethod("cancel_notification", id);
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -442,39 +460,31 @@ class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showInputWarnAlert() async {
|
String getLoginDialogTag(int id) {
|
||||||
if (globalKey.currentContext == null) return;
|
return loginDialogTag + id.toString();
|
||||||
DialogManager.reset();
|
}
|
||||||
await showDialog<bool>(
|
|
||||||
context: globalKey.currentContext!,
|
showInputWarnAlert() {
|
||||||
builder: (alertContext) {
|
DialogManager.show((setState, close) => CustomAlertDialog(
|
||||||
DialogManager.register(alertContext);
|
title: Text(translate("How to get Android input permission?")),
|
||||||
return AlertDialog(
|
content: Column(
|
||||||
title: Text(translate("How to get Android input permission?")),
|
mainAxisSize: MainAxisSize.min,
|
||||||
content: Column(
|
children: [
|
||||||
mainAxisSize: MainAxisSize.min,
|
Text(translate(translate("android_input_permission_tip1"))),
|
||||||
children: [
|
SizedBox(height: 10),
|
||||||
Text(translate(translate("android_input_permission_tip1"))),
|
Text(translate(translate("android_input_permission_tip2"))),
|
||||||
SizedBox(height: 10),
|
|
||||||
Text(translate(translate("android_input_permission_tip2"))),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
child: Text(translate("Cancel")),
|
|
||||||
onPressed: () {
|
|
||||||
DialogManager.reset();
|
|
||||||
}),
|
|
||||||
ElevatedButton(
|
|
||||||
child: Text(translate("Open System Setting")),
|
|
||||||
onPressed: () {
|
|
||||||
FFI.serverModel.initInput();
|
|
||||||
DialogManager.reset();
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
});
|
actions: [
|
||||||
DialogManager.drop();
|
TextButton(child: Text(translate("Cancel")), onPressed: close),
|
||||||
|
ElevatedButton(
|
||||||
|
child: Text(translate("Open System Setting")),
|
||||||
|
onPressed: () {
|
||||||
|
FFI.serverModel.initInput();
|
||||||
|
close();
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class PermissionManager {
|
class PermissionManager {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
||||||
import 'package:flutter_hbb/models/file_model.dart';
|
import 'package:flutter_hbb/models/file_model.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
|
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
|
||||||
import 'package:toggle_switch/toggle_switch.dart';
|
import 'package:toggle_switch/toggle_switch.dart';
|
||||||
@ -27,10 +27,12 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
showLoading(translate('Connecting...'));
|
|
||||||
FFI.connect(widget.id, isFileTransfer: true);
|
FFI.connect(widget.id, isFileTransfer: true);
|
||||||
_interval = Timer.periodic(
|
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||||
Duration(milliseconds: 30), (timer) => FFI.ffiModel.update(widget.id));
|
showLoading(translate('Connecting...'));
|
||||||
|
_interval = Timer.periodic(
|
||||||
|
Duration(milliseconds: 30), (timer) => FFI.ffiModel.update(widget.id));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -38,7 +40,7 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
model.onClose();
|
model.onClose();
|
||||||
_interval?.cancel();
|
_interval?.cancel();
|
||||||
FFI.close();
|
FFI.close();
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
||||||
import 'package:flutter_hbb/models/chat_model.dart';
|
import 'package:flutter_hbb/models/chat_model.dart';
|
||||||
import 'package:flutter_hbb/widgets/gesture_help.dart';
|
import 'package:flutter_hbb/widgets/gesture_help.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
@ -58,7 +58,7 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
FFI.close();
|
FFI.close();
|
||||||
_interval?.cancel();
|
_interval?.cancel();
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
||||||
overlays: SystemUiOverlay.values);
|
overlays: SystemUiOverlay.values);
|
||||||
Wakelock.disable();
|
Wakelock.disable();
|
||||||
@ -800,7 +800,7 @@ void showOptions() {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
if (i == cur) return;
|
if (i == cur) return;
|
||||||
FFI.setByName('switch_display', i.toString());
|
FFI.setByName('switch_display', i.toString());
|
||||||
DialogManager.reset();
|
SmartDialog.dismiss();
|
||||||
},
|
},
|
||||||
child: Ink(
|
child: Ink(
|
||||||
width: 40,
|
width: 40,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hbb/models/model.dart';
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
import 'package:flutter_hbb/widgets/dialog.dart';
|
import 'package:flutter_hbb/widgets/dialog.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
@ -322,7 +323,7 @@ class ConnectionManager extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
clientInfo(entry.value),
|
clientInfo(entry.value),
|
||||||
entry.value.isFileTransfer
|
entry.value.isFileTransfer || !entry.value.authorized
|
||||||
? SizedBox.shrink()
|
? SizedBox.shrink()
|
||||||
: IconButton(
|
: IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -339,16 +340,33 @@ class ConnectionManager extends StatelessWidget {
|
|||||||
))
|
))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ElevatedButton.icon(
|
entry.value.authorized?SizedBox.shrink():Text(
|
||||||
|
translate("android_new_connection_tip"),
|
||||||
|
style: TextStyle(color: Colors.black54),
|
||||||
|
),
|
||||||
|
entry.value.authorized? ElevatedButton.icon(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
MaterialStateProperty.all(Colors.red)),
|
MaterialStateProperty.all(Colors.red)),
|
||||||
icon: Icon(Icons.close),
|
icon: Icon(Icons.close),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
FFI.setByName("close_conn", entry.key.toString());
|
FFI.setByName("close_conn", entry.key.toString());
|
||||||
FFI.invokeMethod("cancel_notification", entry.key);
|
FFI.invokeMethod("cancel_notification", entry.key);
|
||||||
},
|
},
|
||||||
label: Text(translate("Close")))
|
label: Text(translate("Close"))):
|
||||||
|
Row(children: [
|
||||||
|
TextButton(
|
||||||
|
child: Text(translate("Dismiss")),
|
||||||
|
onPressed: () {
|
||||||
|
serverModel.sendLoginResponse(entry.value,false);
|
||||||
|
}),
|
||||||
|
SizedBox(width: 20),
|
||||||
|
ElevatedButton(
|
||||||
|
child: Text(translate("Accept")),
|
||||||
|
onPressed: () {
|
||||||
|
serverModel.sendLoginResponse(entry.value,true);
|
||||||
|
}),
|
||||||
|
]),
|
||||||
],
|
],
|
||||||
)))
|
)))
|
||||||
.toList());
|
.toList());
|
||||||
@ -436,7 +454,7 @@ void toAndroidChannelInit() {
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case "start_capture":
|
case "start_capture":
|
||||||
{
|
{
|
||||||
DialogManager.reset();
|
SmartDialog.dismiss();
|
||||||
FFI.serverModel.updateClientState();
|
FFI.serverModel.updateClientState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
||||||
import 'package:settings_ui/settings_ui.dart';
|
import 'package:settings_ui/settings_ui.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
@ -226,8 +225,7 @@ void logout() async {
|
|||||||
},
|
},
|
||||||
body: json.encode(body));
|
body: json.encode(body));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
EasyLoading.showToast('Failed to access $url',
|
showToast('Failed to access $url');
|
||||||
maskType: EasyLoadingMaskType.black);
|
|
||||||
}
|
}
|
||||||
resetToken();
|
resetToken();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../models/model.dart';
|
import '../models/model.dart';
|
||||||
|
|
||||||
@ -8,20 +8,14 @@ void clientClose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SEC1 = Duration(seconds: 1);
|
const SEC1 = Duration(seconds: 1);
|
||||||
void showSuccess({Duration duration = SEC1}){
|
void showSuccess({Duration duration = SEC1}) {
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
EasyLoading.showSuccess(translate("Successful"),
|
showToast(translate("Successful"),duration:SEC1);
|
||||||
duration: duration,
|
|
||||||
dismissOnTap: true,
|
|
||||||
maskType: EasyLoadingMaskType.black);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void showError({Duration duration = SEC1}){
|
void showError({Duration duration = SEC1}){
|
||||||
EasyLoading.dismiss();
|
SmartDialog.dismiss();
|
||||||
EasyLoading.showError(translate("Error"),
|
showToast(translate("Error"),duration:SEC1);
|
||||||
duration: duration,
|
|
||||||
dismissOnTap: true,
|
|
||||||
maskType: EasyLoadingMaskType.black);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePasswordDialog(){
|
void updatePasswordDialog(){
|
||||||
|
21
pubspec.lock
21
pubspec.lock
@ -202,13 +202,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.1"
|
version: "1.0.1"
|
||||||
flutter_easyloading:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: flutter_easyloading
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "3.0.3"
|
|
||||||
flutter_launcher_icons:
|
flutter_launcher_icons:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -230,13 +223,15 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.5"
|
version: "2.0.5"
|
||||||
flutter_spinkit:
|
flutter_smart_dialog:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_spinkit
|
path: "."
|
||||||
url: "https://pub.dartlang.org"
|
ref: HEAD
|
||||||
source: hosted
|
resolved-ref: "594530edbac758cde29c614046dcc107345ba791"
|
||||||
version: "5.1.0"
|
url: "https://github.com/Heap-Hop/flutter_smart_dialog.git"
|
||||||
|
source: git
|
||||||
|
version: "4.0.0"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -32,7 +32,6 @@ dependencies:
|
|||||||
path_provider: ^2.0.2
|
path_provider: ^2.0.2
|
||||||
external_path: ^1.0.1
|
external_path: ^1.0.1
|
||||||
provider: ^5.0.0
|
provider: ^5.0.0
|
||||||
flutter_easyloading: ^3.0.3
|
|
||||||
tuple: ^2.0.0
|
tuple: ^2.0.0
|
||||||
wakelock: ^0.5.2
|
wakelock: ^0.5.2
|
||||||
device_info: ^2.0.2
|
device_info: ^2.0.2
|
||||||
@ -50,6 +49,9 @@ dependencies:
|
|||||||
zxing2: ^0.1.0
|
zxing2: ^0.1.0
|
||||||
image_picker: ^0.8.5
|
image_picker: ^0.8.5
|
||||||
image: ^3.1.3
|
image: ^3.1.3
|
||||||
|
flutter_smart_dialog:
|
||||||
|
git:
|
||||||
|
url: https://github.com/Heap-Hop/flutter_smart_dialog.git
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: ^0.9.1
|
flutter_launcher_icons: ^0.9.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user