Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: popout problem in edit dialog #49

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/page/homepage/toolbox/sport_card.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright 2023 BenderBlog Rodriguez and contributors.
// SPDX-License-Identifier: MPL-2.0

// import 'dart:math';

import 'package:flutter/material.dart';
import 'package:ming_cute_icons/ming_cute_icons.dart';
// import 'package:talker_flutter/talker_flutter.dart';
import 'package:watermeter/page/public_widget/context_extension.dart';
import 'package:watermeter/page/setting/dialogs/sport_password_dialog.dart';
import 'package:watermeter/page/sport/sport_window.dart';
Expand All @@ -11,16 +14,17 @@ import 'package:watermeter/page/homepage/toolbox/small_function_card.dart';

class SportCard extends StatelessWidget {
const SportCard({super.key});

@override
Widget build(BuildContext context) {
return SmallFunctionCard(
onTap: () async {
bool isGood = true;
if (preference.getString(preference.Preference.sportPassword).isEmpty) {
isGood = await showDialog(
isGood = await showDialog<bool>(
context: context,
builder: (context) => const SportPasswordDialog(),
);
) ?? false; // 当返回值为 null 时,设置 isGood 为 false
}
if (context.mounted && isGood) {
context.pushReplacement(const SportWindow());
Expand Down
4 changes: 2 additions & 2 deletions lib/page/setting/about_page/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ class AboutPage extends StatelessWidget {
),
Link(
icon: Icon(Icons.code),
name: "代码",
name: "开源代码",
url: "https://github.com/BenderBlog/traintime_pda",
),
Link(
icon: Icon(Icons.redeem),
name: "给我捐款",
url: "https://afdian.net/a/benderblog",
url: "https://afdian.com/a/benderblog",
),
];

Expand Down
115 changes: 63 additions & 52 deletions lib/page/setting/dialogs/sport_password_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// Copyright 2023 BenderBlog Rodriguez and contributors.
// SPDX-License-Identifier: MPL-2.0

// Sport password dialog.

import 'package:flutter/material.dart';
import 'package:watermeter/page/public_widget/toast.dart';
import 'package:watermeter/repository/preference.dart' as user_perference;
Expand All @@ -16,65 +11,81 @@ class SportPasswordDialog extends StatefulWidget {

class _SportPasswordDialogState extends State<SportPasswordDialog> {
/// Sport Password Text Editing Controller
final TextEditingController _sportPasswordController =
TextEditingController.fromValue(
TextEditingValue(
text: user_perference.getString(user_perference.Preference.sportPassword),
selection: TextSelection.fromPosition(
TextPosition(
affinity: TextAffinity.downstream,
offset: user_perference
.getString(user_perference.Preference.sportPassword)
.length,
),
),
),
);
final TextEditingController _sportPasswordController = TextEditingController();

bool _couldView = true;

// 用于标识是否通过返回按钮关闭
// bool _wasDismissedViaBackButton = false;

@override
void initState() {
super.initState();
String initialText =
user_perference.getString(user_perference.Preference.sportPassword);
_sportPasswordController.text = initialText;
_sportPasswordController.selection = TextSelection.fromPosition(
TextPosition(offset: initialText.length),
);
}

@override
void dispose() {
_sportPasswordController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('修改体育系统密码'),
content: TextField(
autofocus: true,
controller: _sportPasswordController,
obscureText: _couldView,
decoration: InputDecoration(
hintText: "请在此输入密码",
border: const OutlineInputBorder(),
suffixIcon: IconButton(
return PopScope(
onPopInvoked: (popInvokedCallback) {
// _wasDismissedViaBackButton = true;
popInvokedCallback; // 允许导航器继续处理返回操作
},
child: AlertDialog(
title: const Text('修改体育系统密码'),
content: TextField(
autofocus: true,
controller: _sportPasswordController,
obscureText: _couldView,
decoration: InputDecoration(
hintText: "请在此输入密码",
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: Icon(_couldView ? Icons.visibility : Icons.visibility_off),
onPressed: () {
setState(() {
_couldView = !_couldView;
});
}),
},
),
),
),
actions: <Widget>[
TextButton(
child: const Text('取消'),
onPressed: () {
Navigator.of(context).pop<bool>(false); // 返回 false
},
),
TextButton(
child: const Text('提交'),
onPressed: () async {
if (_sportPasswordController.text.isNotEmpty) {
await user_perference.setString(
user_perference.Preference.sportPassword,
_sportPasswordController.text,
);
if (context.mounted) {
Navigator.of(context).pop<bool>(true); // 返回 true
}
} else {
showToast(context: context, msg: "输入空白!");
}
},
),
],
),
actions: <Widget>[
TextButton(
child: const Text('取消'),
onPressed: () {
Navigator.of(context).pop<bool>(false);
},
),
TextButton(
child: const Text('提交'),
onPressed: () async {
if (_sportPasswordController.text.isNotEmpty) {
user_perference.setString(
user_perference.Preference.sportPassword,
_sportPasswordController.text,
);
Navigator.of(context).pop<bool>(true);
} else {
showToast(context: context, msg: "输入空白!");
}
},
),
],
);
}
}
73 changes: 30 additions & 43 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834
sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7"
url: "https://pub.dev"
source: hosted
version: "72.0.0"
_macros:
dependency: transitive
description: dart
source: sdk
version: "0.3.2"
version: "67.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139
sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d"
url: "https://pub.dev"
source: hosted
version: "6.7.0"
version: "6.4.1"
ansicolor:
dependency: transitive
description:
Expand Down Expand Up @@ -122,18 +117,18 @@ packages:
dependency: "direct dev"
description:
name: build_runner
sha256: dd09dd4e2b078992f42aac7f1a622f01882a8492fef08486b27ddde929c19f04
sha256: "644dc98a0f179b872f612d3eb627924b578897c629788e858157fa5e704ca0c7"
url: "https://pub.dev"
source: hosted
version: "2.4.12"
version: "2.4.11"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0
sha256: e3c79f69a64bdfcd8a776a3c28db4eb6e3fb5356d013ae5eb2e52007706d5dbe
url: "https://pub.dev"
source: hosted
version: "7.3.2"
version: "7.3.1"
built_collection:
dependency: transitive
description:
Expand Down Expand Up @@ -726,18 +721,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.5"
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
Expand Down Expand Up @@ -770,14 +765,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
macros:
dependency: transitive
description:
name: macros
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
url: "https://pub.dev"
source: hosted
version: "0.1.2-main.4"
mailer:
dependency: transitive
description:
Expand Down Expand Up @@ -806,18 +793,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.12.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -1046,10 +1033,10 @@ packages:
dependency: "direct main"
description:
name: restart_app
sha256: ed8b6a3223e90dcd5d9e44c79b66b96f5527a2467ba2b1ec2c242c3807dbd435
sha256: b37daeb1c02fcab30e19d9e30b6fdd215bd53577efd927042eb77cf6f09daadb
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.2.1"
rxdart:
dependency: transitive
description:
Expand Down Expand Up @@ -1219,10 +1206,10 @@ packages:
dependency: transitive
description:
name: sqflite_common
sha256: "7b41b6c3507854a159e24ae90a8e3e9cc01eb26a477c118d6dca065b5f55453e"
sha256: "3da423ce7baf868be70e2c0976c28a1bb2f73644268b7ffa7d2e08eab71f16a4"
url: "https://pub.dev"
source: hosted
version: "2.5.4+2"
version: "2.5.4"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -1267,10 +1254,10 @@ packages:
dependency: "direct main"
description:
name: synchronized
sha256: a824e842b8a054f91a728b783c177c1e4731f6b124f9192468457a8913371255
sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.1.0+1"
talker:
dependency: transitive
description:
Expand Down Expand Up @@ -1315,10 +1302,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.7.2"
version: "0.7.0"
timelines:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1371,10 +1358,10 @@ packages:
dependency: transitive
description:
name: url_launcher_android
sha256: e35a698ac302dd68e41f73250bd9517fe3ab5fa4f18fe4647a0872db61bacbab
sha256: f0c73347dfcfa5b3db8bc06e1502668265d39c08f310c29bff4e28eea9699f79
url: "https://pub.dev"
source: hosted
version: "6.3.10"
version: "6.3.9"
url_launcher_ios:
dependency: transitive
description:
Expand Down Expand Up @@ -1475,10 +1462,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "14.2.5"
version: "14.2.1"
watcher:
dependency: transitive
description:
Expand Down Expand Up @@ -1552,5 +1539,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.5.1 <4.0.0"
flutter: ">=3.24.0"
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"