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

Use initial route instead of home widget #1190

Merged
merged 4 commits into from
Mar 7, 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
13 changes: 7 additions & 6 deletions uni/lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart';
Expand All @@ -20,8 +21,8 @@ import 'messages_pt_PT.dart' as messages_pt_pt;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'en': () => new Future.value(null),
'pt_PT': () => new Future.value(null),
'en': () => new SynchronousFuture(null),
'pt_PT': () => new SynchronousFuture(null),
};

MessageLookupByLibrary? _findExact(String localeName) {
Expand All @@ -36,18 +37,18 @@ MessageLookupByLibrary? _findExact(String localeName) {
}

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) async {
Future<bool> initializeMessages(String localeName) {
var availableLocale = Intl.verifiedLocale(
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new Future.value(false);
return new SynchronousFuture(false);
}
var lib = _deferredLibraries[availableLocale];
await (lib == null ? new Future.value(false) : lib());
lib == null ? new SynchronousFuture(false) : lib();
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new Future.value(true);
return new SynchronousFuture(true);
}

bool _messagesExistFor(String locale) {
Expand Down
14 changes: 8 additions & 6 deletions uni/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -19,12 +20,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

static m0(time) => "last refresh at ${time}";
static String m0(time) => "last refresh at ${time}";

static m1(time) =>
static String m1(time) =>
"${Intl.plural(time, zero: 'Refreshed ${time} minutes ago', one: 'Refreshed ${time} minute ago', other: 'Refreshed ${time} minutes ago')}";

static m2(title) => "${Intl.select(title, {
static String m2(title) => "${Intl.select(title, {
'horario': 'Schedule',
'exames': 'Exams',
'area': 'Personal Area',
Expand All @@ -41,7 +42,7 @@ class MessageLookup extends MessageLookupByLibrary {
})}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function>{
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("About us"),
"academic_services":
MessageLookupByLibrary.simpleMessage("Academic services"),
Expand Down Expand Up @@ -277,7 +278,8 @@ class MessageLookup extends MessageLookupByLibrary {
"terms": MessageLookupByLibrary.simpleMessage("Terms and Conditions"),
"theme": MessageLookupByLibrary.simpleMessage("Theme"),
"title": MessageLookupByLibrary.simpleMessage("Title"),
"uc_info": MessageLookupByLibrary.simpleMessage("Open UC page in app"),
"try_again": MessageLookupByLibrary.simpleMessage("Try again"),
"uc_info": MessageLookupByLibrary.simpleMessage("Open UC page"),
"unavailable": MessageLookupByLibrary.simpleMessage("Unavailable"),
"valid_email":
MessageLookupByLibrary.simpleMessage("Please enter a valid email"),
Expand Down
15 changes: 8 additions & 7 deletions uni/lib/generated/intl/messages_pt_PT.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -19,12 +20,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'pt_PT';

static m0(time) => "última atualização às ${time}";
static String m0(time) => "última atualização às ${time}";

static m1(time) =>
static String m1(time) =>
"${Intl.plural(time, zero: 'Atualizado há ${time} minutos', one: 'Atualizado há ${time} minuto', other: 'Atualizado há ${time} minutos')}";

static m2(title) => "${Intl.select(title, {
static String m2(title) => "${Intl.select(title, {
'horario': 'Horário',
'exames': 'Exames',
'area': 'Área Pessoal',
Expand All @@ -41,7 +42,7 @@ class MessageLookup extends MessageLookupByLibrary {
})}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function>{
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("Sobre nós"),
"academic_services":
MessageLookupByLibrary.simpleMessage("Serviços académicos"),
Expand Down Expand Up @@ -279,8 +280,8 @@ class MessageLookup extends MessageLookupByLibrary {
"terms": MessageLookupByLibrary.simpleMessage("Termos e Condições"),
"theme": MessageLookupByLibrary.simpleMessage("Tema"),
"title": MessageLookupByLibrary.simpleMessage("Título"),
"uc_info":
MessageLookupByLibrary.simpleMessage("Abrir página da UC na app"),
"try_again": MessageLookupByLibrary.simpleMessage("Tentar de novo"),
"uc_info": MessageLookupByLibrary.simpleMessage("Abrir página da UC"),
"unavailable": MessageLookupByLibrary.simpleMessage("Indisponível"),
"valid_email": MessageLookupByLibrary.simpleMessage(
"Por favor insere um email válido"),
Expand Down
10 changes: 10 additions & 0 deletions uni/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion uni/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,7 @@
"confirm_logout": "Do you really want to log out? Your local data will be deleted and you will have to log in again.",
"@confirm_logout": {},
"collect_usage_stats": "Collect usage statistics",
"@usage_stats": {}
"@usage_stats": {},
"try_again": "Try again",
"@try_again": {}
}
4 changes: 3 additions & 1 deletion uni/lib/l10n/intl_pt_PT.arb
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,7 @@
"confirm_logout": "Tens a certeza de que queres terminar sessão? Os teus dados locais serão apagados e terás de iniciar sessão novamente.",
"@confirm_logout": {},
"collect_usage_stats": "Partilhar estatísticas de uso",
"@collect_usage_stats": {}
"@collect_usage_stats": {},
"try_again": "Tentar de novo",
"@try_again": {}
}
18 changes: 11 additions & 7 deletions uni/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ SentryEvent? beforeSend(SentryEvent event) {
return event.level == SentryLevel.info ? event : null;
}

Future<Widget> firstRoute() async {
Future<String> firstRoute() async {
final userPersistentInfo = PreferencesController.getPersistentUserInfo();

if (userPersistentInfo != null) {
return const HomePageView();
return '/${NavigationItem.navPersonalArea.route}';
}

await acceptTermsAndConditions();
return const LoginPageView();
return '/${NavigationItem.navLogin.route}';
}

Future<void> main() async {
Expand Down Expand Up @@ -184,9 +184,9 @@ Future<void> main() async {
/// This class is necessary to track the app's state for
/// the current execution.
class Application extends StatefulWidget {
const Application(this.initialWidget, {super.key});
const Application(this.initialRoute, {super.key});

final Widget initialWidget;
final String initialRoute;

static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

Expand Down Expand Up @@ -228,11 +228,15 @@ class ApplicationState extends State<Application> {
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
initialRoute: '/${NavigationItem.navPersonalArea.route}',
home: widget.initialWidget,
initialRoute: widget.initialRoute,
navigatorObservers: navigatorObservers,
onGenerateRoute: (RouteSettings settings) {
final transitions = {
'/${NavigationItem.navLogin.route}':
PageTransition.makePageTransition(
page: const LoginPageView(),
settings: settings,
),
'/${NavigationItem.navPersonalArea.route}':
PageTransition.makePageTransition(
page: const HomePageView(),
Expand Down
1 change: 1 addition & 0 deletions uni/lib/model/providers/state_provider_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ abstract class StateProviderNotifier<T> extends ChangeNotifier {
/// so that consumers may trigger the loading again.
void invalidate() {
_state = null;
notifyListeners();
}

Future<void> _loadFromStorage(BuildContext context) async {
Expand Down
3 changes: 2 additions & 1 deletion uni/lib/utils/navigation_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ enum NavigationItem {
navAcademicPath('percurso_academico'),
navProfile('perfil'),
navSettings('definicoes'),
navTransports('transportes');
navTransports('transportes'),
navLogin('login');

const NavigationItem(this.route, {this.faculties});

Expand Down
59 changes: 0 additions & 59 deletions uni/lib/view/common_widgets/widgets/request_failed_message.dart

This file was deleted.

27 changes: 20 additions & 7 deletions uni/lib/view/lazy_consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,27 @@ class LazyConsumer<T1 extends StateProviderNotifier<T2>, T2>
),
),
),
OutlinedButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute<BugReportPageView>(
builder: (context) => const BugReportPageView(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
OutlinedButton(
onPressed: () => Provider.of<T1>(context, listen: false)
.forceRefresh(context),
child: Text(S.of(context).try_again),
),
),
child: Text(S.of(context).report_error),
const SizedBox(
width: 10,
),
OutlinedButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute<BugReportPageView>(
builder: (context) => const BugReportPageView(),
),
),
child: Text(S.of(context).report_error),
),
],
),
],
);
Expand Down
4 changes: 4 additions & 0 deletions uni/lib/view/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class LoginPageViewState extends State<LoginPageView> {
pass,
persistentSession: _keepSignedIn,
);

usernameController.clear();
passwordController.clear();

if (context.mounted) {
await Navigator.pushReplacementNamed(
context,
Expand Down
Loading