opt.: no app restart required
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/core/extension/context/common.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
|
||||
import '../../../data/model/server/snippet.dart';
|
||||
@@ -41,37 +41,35 @@ extension DialogX on BuildContext {
|
||||
String? user,
|
||||
) async {
|
||||
if (!mounted) return null;
|
||||
final s = S.of(this)!;
|
||||
return await showRoundDialog<String>(
|
||||
title: Text(user ?? s.pwd),
|
||||
title: Text(user ?? l10n.pwd),
|
||||
child: Input(
|
||||
autoFocus: true,
|
||||
type: TextInputType.visiblePassword,
|
||||
obscureText: true,
|
||||
onSubmitted: (val) => pop(val.trim()),
|
||||
label: s.pwd,
|
||||
label: l10n.pwd,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showSnippetDialog(
|
||||
S s,
|
||||
void Function(Snippet s) onSelected,
|
||||
) {
|
||||
if (Providers.snippet.snippets.isEmpty) {
|
||||
showRoundDialog(
|
||||
child: Text(s.noSavedSnippet),
|
||||
child: Text(l10n.noSavedSnippet),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => pop(),
|
||||
child: Text(s.ok),
|
||||
child: Text(l10n.ok),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
pop();
|
||||
AppRoute.snippetEdit().go(this);
|
||||
},
|
||||
child: Text(s.add),
|
||||
child: Text(l10n.add),
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -80,7 +78,7 @@ extension DialogX on BuildContext {
|
||||
|
||||
var snippet = Providers.snippet.snippets.first;
|
||||
showRoundDialog(
|
||||
title: Text(s.choose),
|
||||
title: Text(l10n.choose),
|
||||
child: Picker(
|
||||
items: Providers.snippet.snippets.map((e) => Text(e.name)).toList(),
|
||||
onSelected: (idx) => snippet = Providers.snippet.snippets[idx],
|
||||
@@ -91,7 +89,7 @@ extension DialogX on BuildContext {
|
||||
pop();
|
||||
onSelected(snippet);
|
||||
},
|
||||
child: Text(s.ok),
|
||||
child: Text(l10n.ok),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
7
lib/core/extension/context/locale.dart
Normal file
7
lib/core/extension/context/locale.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
late S _s;
|
||||
S get l10n => _s;
|
||||
set l10n(S s) {
|
||||
_s = s;
|
||||
}
|
||||
@@ -2,10 +2,10 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:r_upgrade/r_upgrade.dart';
|
||||
import 'package:toolbox/core/extension/context/common.dart';
|
||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/extension/context/snackbar.dart';
|
||||
import 'package:toolbox/core/utils/platform/base.dart';
|
||||
import 'package:toolbox/data/model/app/update.dart';
|
||||
@@ -54,17 +54,15 @@ Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
return;
|
||||
}
|
||||
|
||||
final s = S.of(context);
|
||||
|
||||
final min = update.build.min.current;
|
||||
|
||||
if (min != null && min > BuildData.build) {
|
||||
context.showRoundDialog(
|
||||
child: Text(s?.updateTipTooLow(newest) ?? 'Update: $newest'),
|
||||
child: Text(l10n.updateTipTooLow(newest)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => _doUpdate(update, context, s),
|
||||
child: Text(s?.ok ?? 'Ok'),
|
||||
onPressed: () => _doUpdate(update, context),
|
||||
child: Text(l10n.ok),
|
||||
)
|
||||
],
|
||||
);
|
||||
@@ -72,13 +70,13 @@ Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
}
|
||||
|
||||
context.showSnackBarWithAction(
|
||||
'${s?.updateTip(newest) ?? "Update: $newest"} \n${update.changelog.current}',
|
||||
s?.update ?? 'Update',
|
||||
() => _doUpdate(update, context, s),
|
||||
'${l10n.updateTip(newest)} \n${update.changelog.current}',
|
||||
l10n.update,
|
||||
() => _doUpdate(update, context),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _doUpdate(AppUpdate update, BuildContext context, S? s) async {
|
||||
Future<void> _doUpdate(AppUpdate update, BuildContext context) async {
|
||||
final url = update.url.current;
|
||||
if (url == null) return;
|
||||
|
||||
@@ -91,11 +89,11 @@ Future<void> _doUpdate(AppUpdate update, BuildContext context, S? s) async {
|
||||
await openUrl(url);
|
||||
} else {
|
||||
context.showRoundDialog(
|
||||
child: Text(s?.platformNotSupportUpdate ?? 'Unsupported platform'),
|
||||
child: Text(l10n.platformNotSupportUpdate),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
child: Text(s?.ok ?? 'Ok'),
|
||||
child: Text(l10n.ok),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
@@ -3,9 +3,9 @@ import 'package:crypto/crypto.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:plain_notification_token/plain_notification_token.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/core/utils/platform/base.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
|
||||
@@ -19,7 +19,7 @@ Future<bool> shareFiles(BuildContext context, List<String> filePaths) async {
|
||||
if (filePaths.length == 1) {
|
||||
text = filePaths.first.split('/').last;
|
||||
} else {
|
||||
text = '${filePaths.length} ${S.of(context)!.files}';
|
||||
text = '${filePaths.length} ${l10n.files}';
|
||||
}
|
||||
Providers.app.moveBg = false;
|
||||
// ignore: deprecated_member_use
|
||||
|
||||
@@ -5,23 +5,23 @@ class _RebuildNode implements ValueListenable<Null> {
|
||||
final List<VoidCallback> _listeners = [];
|
||||
|
||||
_RebuildNode();
|
||||
|
||||
|
||||
@override
|
||||
void addListener(VoidCallback listener) {
|
||||
_listeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void removeListener(VoidCallback listener) {
|
||||
_listeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
void rebuild() {
|
||||
for (var listener in _listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Null get value => null;
|
||||
}
|
||||
@@ -30,4 +30,4 @@ class RebuildNodes {
|
||||
const RebuildNodes._();
|
||||
|
||||
static final _RebuildNode app = _RebuildNode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user