Skip to content

Commit

Permalink
Fix title may always be default title
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc authored Jun 3, 2024
1 parent 727d3ec commit 760f36c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final _router = GoRouter(
routes: [
GoRoute(
path: HomePage.routeName,
builder: (context, state) => const HomePage(),
builder: (context, state) => HomePage(key: state.pageKey),
),
GoRoute(
path: ServerUrlSettingsPage.routeName,
Expand Down Expand Up @@ -212,7 +212,7 @@ final _router = GoRouter(
}),
GoRoute(
path: UsersPage.routeName,
builder: (context, state) => const UsersPage(),
builder: (context, state) => UsersPage(key: state.pageKey),
),
GoRoute(
path: NewUserPage.routeName,
Expand Down
7 changes: 5 additions & 2 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class HomeDrawer extends StatelessWidget {
}
}

class HomePage extends HookWidget {
class HomePage extends HookWidget with IsTopWidget {
const HomePage({super.key});

static const String routeName = '/';
Expand All @@ -75,7 +75,10 @@ class HomePage extends HookWidget {
tryInitApi(context);
var mode = useState(MainApp.of(context).themeMode);
mode.value = MainApp.of(context).themeMode;
setCurrentTitle("", Theme.of(context).primaryColor.value, usePrefix: true);
if (isTop(context)) {
setCurrentTitle("", Theme.of(context).primaryColor.value,
usePrefix: true);
}
return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context)!.titleBar),
Expand Down
23 changes: 11 additions & 12 deletions lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ class _LoginPageState extends State<LoginPage>
_tryPoped = true;
return Container();
}
final i18n = AppLocalizations.of(context)!;
if (isTop(context)) {
setCurrentTitle(i18n.login, Theme.of(context).primaryColor.value);
}
return Scaffold(
appBar: AppBar(
leading: Container(),
title: Text(AppLocalizations.of(context)!.login),
title: Text(i18n.login),
actions: [
buildThemeModeIcon(context),
buildMoreVertSettingsButon(context),
Expand All @@ -153,8 +157,7 @@ class _LoginPageState extends State<LoginPage>
child: TextFormField(
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText:
AppLocalizations.of(context)!.username,
labelText: i18n.username,
),
initialValue: _username,
onChanged: _usernameChanged,
Expand All @@ -164,8 +167,7 @@ class _LoginPageState extends State<LoginPage>
child: TextFormField(
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText:
AppLocalizations.of(context)!.password,
labelText: i18n.password,
suffixIcon: IconButton(
icon: Icon(
_passwordVisible
Expand Down Expand Up @@ -195,8 +197,7 @@ class _LoginPageState extends State<LoginPage>
} else {
final snackBar = SnackBar(
content: Text(
AppLocalizations.of(context)!
.incorrectUserPassword));
i18n.incorrectUserPassword));
ScaffoldMessenger.of(context)
.showSnackBar(snackBar);
setState(() {
Expand All @@ -209,10 +210,8 @@ class _LoginPageState extends State<LoginPage>
e is! (int, String);
final snackBar = SnackBar(
content: Text(isNetworkError
? AppLocalizations.of(context)!
.networkError
: AppLocalizations.of(context)!
.internalError));
? i18n.networkError
: i18n.internalError));
ScaffoldMessenger.of(context)
.showSnackBar(snackBar);
setState(() {
Expand All @@ -221,7 +220,7 @@ class _LoginPageState extends State<LoginPage>
});
}
: null,
child: Text(AppLocalizations.of(context)!.login)),
child: Text(i18n.login)),
])))),
);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/pages/settings/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class CacheSettingsPage extends StatefulWidget {
State<CacheSettingsPage> createState() => _CacheSettingsPage();
}

class _CacheSettingsPage extends State<CacheSettingsPage> with ThemeModeWidget {
class _CacheSettingsPage extends State<CacheSettingsPage>
with ThemeModeWidget, IsTopWidget2 {
bool _oriEnableImageCache = false;
bool _enableImageCache = false;
@override
Expand Down Expand Up @@ -103,8 +104,10 @@ class _CacheSettingsPage extends State<CacheSettingsPage> with ThemeModeWidget {
@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context)!;
setCurrentTitle("${i18n.settings} - ${i18n.cache}",
Theme.of(context).primaryColor.value);
if (isTop(context)) {
setCurrentTitle("${i18n.settings} - ${i18n.cache}",
Theme.of(context).primaryColor.value);
}
return Scaffold(
appBar: AppBar(
leading: IconButton(
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/settings/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DisplaySettingsPage extends StatefulWidget {
}

class _DisplaySettingsPage extends State<DisplaySettingsPage>
with ThemeModeWidget {
with ThemeModeWidget, IsTopWidget2 {
bool _oriDisplayAd = false;
Lang _oriLang = Lang.system;
bool _oriPreventScreenCapture = false;
Expand Down Expand Up @@ -185,8 +185,10 @@ class _DisplaySettingsPage extends State<DisplaySettingsPage>
@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context)!;
setCurrentTitle("${i18n.settings} - ${i18n.display}",
Theme.of(context).primaryColor.value);
if (isTop(context)) {
setCurrentTitle("${i18n.settings} - ${i18n.display}",
Theme.of(context).primaryColor.value);
}
return Scaffold(
appBar: AppBar(
leading: IconButton(
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/settings/server_url.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ServerUrlSettingsPage extends StatefulWidget {
}

class _ServerUrlSettingsPage extends State<ServerUrlSettingsPage>
with ThemeModeWidget {
with ThemeModeWidget, IsTopWidget2 {
String _serverUrl = "";
String _apiPath = "/api/";
bool _isValid = false;
Expand Down Expand Up @@ -78,8 +78,10 @@ class _ServerUrlSettingsPage extends State<ServerUrlSettingsPage>
buildThemeModeIcon(context),
];
if (hasBaseUrl) actions.add(buildMoreVertSettingsButon(context));
setCurrentTitle("${i18n.settings} - ${i18n.setServerUrl}",
Theme.of(context).primaryColor.value);
if (isTop(context)) {
setCurrentTitle("${i18n.settings} - ${i18n.setServerUrl}",
Theme.of(context).primaryColor.value);
}
return Scaffold(
appBar: AppBar(
title: Text(i18n.setServerUrl),
Expand Down
9 changes: 6 additions & 3 deletions lib/pages/settings/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ class UserSettingsPage extends StatefulWidget {
State<StatefulWidget> createState() => _UserSettingsPage();
}

class _UserSettingsPage extends State<UserSettingsPage> with ThemeModeWidget {
class _UserSettingsPage extends State<UserSettingsPage>
with ThemeModeWidget, IsTopWidget2 {
void _onStateChanged(dynamic _) {
setState(() {});
}
Expand Down Expand Up @@ -310,8 +311,10 @@ class _UserSettingsPage extends State<UserSettingsPage> with ThemeModeWidget {
@override
Widget build(BuildContext context) {
final i18n = AppLocalizations.of(context)!;
setCurrentTitle("${i18n.settings} - ${i18n.user}",
Theme.of(context).primaryColor.value);
if (isTop(context)) {
setCurrentTitle("${i18n.settings} - ${i18n.user}",
Theme.of(context).primaryColor.value);
}
return Scaffold(
appBar: AppBar(
leading: IconButton(
Expand Down

0 comments on commit 760f36c

Please sign in to comment.