Skip to content

Commit

Permalink
Allow change settings in login page
Browse files Browse the repository at this point in the history
Fix layout
  • Loading branch information
lifegpc committed May 30, 2024
1 parent 69929d6 commit fb21e0c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 30 deletions.
7 changes: 4 additions & 3 deletions lib/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,17 @@ void clearAllStates(BuildContext context) {

void checkAuth(BuildContext context) {
if (!auth.isAuthed && !auth.checked && !auth.isChecking) {
final state = GoRouterState.of(context);
final router = GoRouter.of(context);
auth.checkAuth().then((re) {
if (!re) {
if (auth.status!.noUser &&
prefs.getBool("skipCreateRootUser") == true) {
return;
}
final loc = auth.status!.noUser ? "/create_root_user" : "/login";
final path = GoRouterState.of(context).path;
if (path != loc) {
context.push(loc);
if (state.path != loc) {
router.push(loc);
}
}
}).catchError((err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final _router = GoRouter(
),
GoRoute(
path: LoginPage.routeName,
builder: (context, state) => const LoginPage(),
builder: (context, state) => LoginPage(key: state.pageKey),
),
GoRoute(
path: CreateRootUserPage.routeName,
Expand Down
29 changes: 21 additions & 8 deletions lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Future<bool> login(String username, String password) async {
throw re.unwrapErr();
}

class _LoginPageState extends State<LoginPage> with ThemeModeWidget {
class _LoginPageState extends State<LoginPage>
with ThemeModeWidget, IsTopWidget2 {
final _formKey = GlobalKey<FormState>();
String _username = "";
String _password = "";
Expand All @@ -45,6 +46,10 @@ class _LoginPageState extends State<LoginPage> with ThemeModeWidget {
bool _isLogin = false;
bool _checkAuth = false;

void _onStateChanged(dynamic _) {
setState(() {});
}

@override
void initState() {
super.initState();
Expand All @@ -53,6 +58,13 @@ class _LoginPageState extends State<LoginPage> with ThemeModeWidget {
_passwordVisible = false;
_isValid = false;
_isLogin = false;
listener.on("user_logined", _onStateChanged);
}

@override
void dispose() {
listener.removeEventListener("user_logined", _onStateChanged);
super.dispose();
}

static bool _checkIsValid(String username, String password) {
Expand Down Expand Up @@ -82,6 +94,7 @@ class _LoginPageState extends State<LoginPage> with ThemeModeWidget {
}

void _checkStatus(BuildContext build) {
if (!isTop(context)) return;
if (auth.isAuthed) {
SchedulerBinding.instance.addPostFrameCallback((_) {
build.go("/");
Expand All @@ -107,18 +120,18 @@ class _LoginPageState extends State<LoginPage> with ThemeModeWidget {
Widget build(BuildContext context) {
tryInitApi(context);
_checkStatus(context);
if (isTop(context) && auth.user != null) {
SchedulerBinding.instance.addPostFrameCallback((_) {
context.canPop() ? context.pop() : context.go("/");
});
}
return Scaffold(
appBar: AppBar(
leading: auth.user == null
? Container()
: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
context.canPop() ? context.pop() : context.go("/");
}),
leading: Container(),
title: Text(AppLocalizations.of(context)!.login),
actions: [
buildThemeModeIcon(context),
buildMoreVertSettingsButon(context),
],
),
body: PopScope(
Expand Down
1 change: 1 addition & 0 deletions lib/pages/settings/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class _DisplaySettingsPage extends State<DisplaySettingsPage>
: e.langName))
.toList(),
leadingIcon: const Icon(Icons.language),
width: 250,
)),
Container(
padding:
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/users.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class _UsersPage extends State<UsersPage> with ThemeModeWidget, IsTopWidget2 {
Widget _buildSliverGrid(BuildContext context) {
return SliverGrid(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 360.0,
maxCrossAxisExtent: 370.0,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
mainAxisExtent: 80.0,
Expand Down
1 change: 1 addition & 0 deletions lib/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TaskManager {
tasksList.clear();
_channel?.sink.add("{\"type\":\"close\"}");
_channel?.sink.close();
_channel = null;
_closed = true;
}

Expand Down
34 changes: 17 additions & 17 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: "6ad5662b014c06c20fa46ab78715c96b2222a7fe4f87bf77e0289592c2539e86"
sha256: abec47eb8c8c36ebf41d0a4c64dbbe7f956e39a012b3aafc530e951bdc12fe3f
url: "https://pub.dev"
source: hosted
version: "14.1.3"
version: "14.1.4"
graphs:
dependency: transitive
description:
Expand Down Expand Up @@ -618,10 +618,10 @@ packages:
dependency: transitive
description:
name: path_provider_android
sha256: a248d8146ee5983446bf03ed5ea8f6533129a12b11f12057ad1b4a67a2b3b41d
sha256: "9c96da072b421e98183f9ea7464898428e764bc0ce5567f27ec8693442e72514"
url: "https://pub.dev"
source: hosted
version: "2.2.4"
version: "2.2.5"
path_provider_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -730,10 +730,10 @@ packages:
dependency: transitive
description:
name: pubspec_parse
sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367
sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8
url: "https://pub.dev"
source: hosted
version: "1.2.3"
version: "1.3.0"
retrofit:
dependency: "direct main"
description:
Expand Down Expand Up @@ -770,10 +770,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_android
sha256: "1ee8bf911094a1b592de7ab29add6f826a7331fb854273d55918693d5364a1f2"
sha256: "93d0ec9dd902d85f326068e6a899487d1f65ffcd5798721a95330b26c8131577"
url: "https://pub.dev"
source: hosted
version: "2.2.2"
version: "2.2.3"
shared_preferences_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -943,26 +943,26 @@ packages:
dependency: "direct main"
description:
name: super_clipboard
sha256: f81058a9b3cadaaf60f37c2a37dd2647c6e5eda4533e335f1512605e3b9fb860
sha256: "17978c3dc7b6ebf588a8007448f668ad6aa64733b60ed2ae18152113cca39fa2"
url: "https://pub.dev"
source: hosted
version: "0.8.15"
version: "0.8.16"
super_context_menu:
dependency: "direct main"
description:
name: super_context_menu
sha256: "8a5fef2ca0dcb207fef7168c4c00079e649bfc24223a8f72e3cfcf6b7083e89e"
sha256: "33f189fd508716d03daa277d890a8b079f691e3e3577d99d81c1e23b2a9968c7"
url: "https://pub.dev"
source: hosted
version: "0.8.15"
version: "0.8.16"
super_native_extensions:
dependency: transitive
description:
name: super_native_extensions
sha256: bb6499c83484c1dbe293e68907a9b6d51e30b699502c5e11940e834c310df261
sha256: d2d1259c7e43966173c394ef64475e612bd5822095f6cd1008eb978175ce2f0d
url: "https://pub.dev"
source: hosted
version: "0.8.15"
version: "0.8.16"
synchronized:
dependency: transitive
description:
Expand Down Expand Up @@ -1079,10 +1079,10 @@ packages:
dependency: transitive
description:
name: web_socket
sha256: "217f49b5213796cb508d6a942a5dc604ce1cb6a0a6b3d8cb3f0c314f0ecea712"
sha256: "24301d8c293ce6fe327ffe6f59d8fd8834735f0ec36e4fd383ec7ff8a64aa078"
url: "https://pub.dev"
source: hosted
version: "0.1.4"
version: "0.1.5"
web_socket_channel:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1141,4 +1141,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.19.0"
flutter: ">=3.22.0"

0 comments on commit fb21e0c

Please sign in to comment.