mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-23 16:45:27 +01:00
opt.: add tip for upgrading pkgs (#326)
This commit is contained in:
69
lib/view/widget/count_down_btn.dart
Normal file
69
lib/view/widget/count_down_btn.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
|
||||
final class CountDownBtn extends StatefulWidget {
|
||||
final int seconds;
|
||||
final String text;
|
||||
final Color? afterColor;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const CountDownBtn({
|
||||
super.key,
|
||||
required this.onTap,
|
||||
this.seconds = 3,
|
||||
this.text = 'Go',
|
||||
this.afterColor,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CountDownBtn> createState() => _CountDownBtnState();
|
||||
}
|
||||
|
||||
final class _CountDownBtnState extends State<CountDownBtn> {
|
||||
late int _seconds = widget.seconds;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_startCountDown();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get isCounting => _seconds > 0;
|
||||
|
||||
void _startCountDown() {
|
||||
if (isCounting) return;
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (!isCounting) {
|
||||
_timer?.cancel();
|
||||
}
|
||||
setState(() {
|
||||
_seconds--;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
if (isCounting) return;
|
||||
widget.onTap();
|
||||
},
|
||||
child: Text(
|
||||
isCounting ? '$_seconds${l10n.second}' : widget.text,
|
||||
style: TextStyle(
|
||||
color: _seconds > 0 ? Colors.grey : widget.afterColor,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import 'package:toolbox/data/res/path.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/data/res/ui.dart';
|
||||
import 'package:toolbox/view/widget/count_down_btn.dart';
|
||||
|
||||
import '../../core/route.dart';
|
||||
import '../../core/utils/server.dart';
|
||||
@@ -279,12 +280,13 @@ Future<void> _onPkg(BuildContext context, ServerPrivateInfo spi) async {
|
||||
final gotoUpgrade = await context.showRoundDialog<bool>(
|
||||
title: Text(l10n.attention),
|
||||
child: SingleChildScrollView(
|
||||
child: Text('${l10n.foundNUpdate(upgradeable.length)}\n\n$upgradeCmd'),
|
||||
child: Text('${l10n.pkgUpgradeTip}\n${l10n.foundNUpdate(upgradeable.length)}\n\n$upgradeCmd'),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(l10n.update),
|
||||
CountDownBtn(
|
||||
onTap: () => context.pop(true),
|
||||
text: l10n.update,
|
||||
afterColor: Colors.red,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user