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

UI/connectivity warning #1412

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions packages/uni_app/assets/images/circle-alert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion packages/uni_app/lib/view/academic_path/academic_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/academic_path/widgets/course_units_card.dart';
import 'package:uni/view/common_widgets/connectivity_warning_card.dart';
import 'package:uni/view/common_widgets/generic_card.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/home/widgets/exam_card.dart';
Expand Down Expand Up @@ -29,7 +30,10 @@ class AcademicPathPageViewState extends GeneralPageViewState {
@override
Widget getBody(BuildContext context) {
return ListView(
children: academicPathCards,
children: [
const ConnectivityWarning(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the position of the ConnectivityWarning fixed, move it to the getTopNavBar method in GeneralPageViewState (however, note that the layout of the pages may change during the redesign).

Copy link
Contributor Author

@jcovaa jcovaa Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the conversation we had, I tried to change the _createTopWodgets method in the top_navigation_bar.dart class but there are 2 problems. The first is that the home page uses a getHeader method that creates the tittle differently from the other pages (the warning appears above instead of below the tittle). The second problem is that the size of the AppBar isnt dynamically changed when the warning is displayed, so it seems cut out. Do I have to increase its size or its my implementation that isnt correct?

...academicPathCards,
],
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

import '../../generated/l10n.dart';

class ConnectivityWarning extends StatefulWidget {
const ConnectivityWarning({super.key});

@override
State<ConnectivityWarning> createState() => _ConnectivityWarningState();
}

class _ConnectivityWarningState extends State<ConnectivityWarning> {
bool isOffline = false;

StreamSubscription<ConnectivityResult>? connectivitySubscription;

@override
void initState() {
super.initState();
checkInitialConnection();

connectivitySubscription = Connectivity()
.onConnectivityChanged
.listen((result) {
setState(() {
isOffline = result == ConnectivityResult.none;
});
});
}

Future<void> checkInitialConnection() async {
final result = await Connectivity().checkConnectivity();
setState(() {
isOffline = result == ConnectivityResult.none;
});
}

@override
void dispose() {
connectivitySubscription?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Visibility(
visible: isOffline,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 20),
child: Row(
children: [
SvgPicture.asset('assets/images/circle-alert.svg',
colorFilter: ColorFilter.mode(
Theme.of(context).primaryColor,
BlendMode.srcIn,
),
width: 21,
height: 21,
),
const SizedBox(width: 8),
Text(
S.of(context).internet_status_exception,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
);
}
}
2 changes: 2 additions & 0 deletions packages/uni_app/lib/view/faculty/faculty.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:uni/generated/l10n.dart';
import 'package:uni/model/providers/lazy/library_occupation_provider.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/calendar/widgets/calendar_card.dart';
import 'package:uni/view/common_widgets/connectivity_warning_card.dart';
import 'package:uni/view/common_widgets/generic_expansion_card.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/faculty/widgets/academic_services_card.dart';
Expand Down Expand Up @@ -31,6 +32,7 @@ class FacultyPageViewState extends GeneralPageViewState {
Widget getBody(BuildContext context) {
return ListView(
children: [
const ConnectivityWarning(),
LibraryOccupationCard(),
CalendarCard(),
...getUtilsSection(),
Expand Down
64 changes: 35 additions & 29 deletions packages/uni_app/lib/view/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:uni/controller/local_storage/preferences_controller.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/utils/favorite_widget_type.dart';
import 'package:uni/view/common_widgets/connectivity_warning_card.dart';
import 'package:uni/view/common_widgets/page_title.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/widgets/profile_button.dart';
Expand Down Expand Up @@ -49,36 +50,41 @@ class HomePageViewState extends GeneralPageViewState {

@override
Widget? getHeader(BuildContext context) {
return Container(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
PageTitle(
name: S.of(context).nav_title('area'),
center: false,
pad: false,
),
if (isEditing)
ElevatedButton(
onPressed: () => setState(() {
isEditing = false;
}),
child: Text(
S.of(context).edit_on,
),
)
else
OutlinedButton(
onPressed: () => setState(() {
isEditing = true;
}),
child: Text(
S.of(context).edit_off,
return Column(
children: [
Container(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
PageTitle(
name: S.of(context).nav_title('area'),
center: false,
pad: false,
),
),
],
),
if (isEditing)
ElevatedButton(
onPressed: () => setState(() {
isEditing = false;
}),
child: Text(
S.of(context).edit_on,
),
)
else
OutlinedButton(
onPressed: () => setState(() {
isEditing = true;
}),
child: Text(
S.of(context).edit_off,
),
),
],
),
),
const ConnectivityWarning(),
],
);
}

Expand Down
15 changes: 11 additions & 4 deletions packages/uni_app/lib/view/restaurant/restaurant_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:uni/model/entities/restaurant.dart';
import 'package:uni/model/providers/lazy/restaurant_provider.dart';
import 'package:uni/model/utils/day_of_week.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/common_widgets/connectivity_warning_card.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/lazy_consumer.dart';
import 'package:uni/view/locale_notifier.dart';
Expand Down Expand Up @@ -47,13 +48,19 @@ class _RestaurantPageViewState extends GeneralPageViewState<RestaurantPageView>

@override
Widget? getHeader(BuildContext context) {
return TabBar(
controller: tabController,
isScrollable: true,
tabs: createTabs(context),
return Column(
children: [
const ConnectivityWarning(),
TabBar(
controller: tabController,
isScrollable: true,
tabs: createTabs(context),
),
],
);
}


@override
Widget getBody(BuildContext context) {
return LazyConsumer<RestaurantProvider, List<Restaurant>>(
Expand Down
6 changes: 5 additions & 1 deletion packages/uni_app/lib/view/transports/transports.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/utils/navigation_items.dart';
import 'package:uni/view/common_widgets/connectivity_warning_card.dart';
import 'package:uni/view/common_widgets/generic_card.dart';
import 'package:uni/view/common_widgets/pages_layouts/general/general.dart';
import 'package:uni/view/home/widgets/bus_stop_card.dart';
Expand All @@ -27,7 +28,10 @@ class TransportsPageViewState extends GeneralPageViewState {
@override
Widget getBody(BuildContext context) {
return ListView(
children: transportsCards,
children: [
const ConnectivityWarning(),
...transportsCards,
],
);
}

Expand Down
Loading