Skip to content

Commit

Permalink
Allow resizing schedule settings (#899)
Browse files Browse the repository at this point in the history
* Permettre de modifier la taille

* Fonctionne, excepté que je n'ai pas pu mettre le listtiletheme

* Fixed visual bugs

* Fix pas d'update du calendrier

* Fix tests

* [BOT] Applying version.

* [BOT] Applying format.

* [BOT] Update golden files

* Adding tests

* [BOT] Applying format.

* Migrate service classes to null safety

* Migrate constants to null safety

* Migrate utils to null safety

* Remove late from GetIt

* Change @required to required

* Migrate models to null safety

* Migrate main to null safety

* Migrate managers to null safety

* Migrate ViewModels to null safety

* Migrate utils to null safety

* Migrate views to null safety

* Migrate Views to null safety

* Migrate mocks to null safety

* Use late for all tests

* Fix service tests

* Migrate helpers to null safety

* Migrate managers tests to null safety

* Migrate ViewModel tests to null safety

* Managers use mocks for managers

* Migrate widget tests to null safety

* Migrate views tests to null safety

* Fix course_repository_test

* Fix QuickLinkRepository tests

* Fix SettingsManagerTests

* Fix user repository tests

* Fix GradeEvaluationTile tests

* Fix code problems

* Fix DashboardViewModel tests

* Fix FeedbackViewModelTest

* Fix GradeViewModel tests

* Fix UserRepositoryMock tests

* Fix ScheduleSettingsViewModel tests

* Fix ScheduleViewModel tests

* Fix GradeDetailsView tests

* Fix NotFoundView test

* Fix GradeDetailsViewModel tests

* Fix ScheduleViewModel tests

* Remove use of Future OnError

* [BOT] Applying version.

* [BOT] Applying format.

* [BOT] Applying version.

* Fix warning

* Fix test

* [BOT] Update golden files

---------

Co-authored-by: LouisPhilippeHeon <LouisPhilippeHeon@users.noreply.github.com>
Co-authored-by: clubapplets-server <clubapplets-server@users.noreply.github.com>
Co-authored-by: Xavier Paquet-Rapold <xavier.paquet-rapold.1@ens.etsmtl.ca>
  • Loading branch information
4 people authored Mar 21, 2024
1 parent 4ea7e6f commit 79ecf5c
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 68 deletions.
16 changes: 9 additions & 7 deletions lib/ui/views/schedule_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class _ScheduleViewState extends State<ScheduleView>
ViewModelBuilder<ScheduleViewModel>.reactive(
viewModelBuilder: () => ScheduleViewModel(
intl: AppIntl.of(context)!, initialSelectedDate: widget.initialDay),
onModelReady: (model) {
if (model.settings.isEmpty) {
model.loadSettings();
}
},
builder: (context, model, child) => BaseScaffold(
isLoading: model.busy(model.isLoadingEvents),
isInteractionLimitedWhileLoading: false,
Expand Down Expand Up @@ -511,14 +516,11 @@ class _ScheduleViewState extends State<ScheduleView>
onPressed: () async {
_analyticsService.logEvent(tag, "Settings clicked");
await showModalBottomSheet(
isDismissible: true,
enableDrag: true,
isScrollControlled: true,
context: context,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10))),
borderRadius:
BorderRadius.vertical(top: Radius.circular(10))),
context: context,
isScrollControlled: true,
builder: (context) => const ScheduleSettings());
model.loadSettings();
}));
Expand Down
129 changes: 72 additions & 57 deletions lib/ui/widgets/schedule_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,80 @@ class _ScheduleSettingsState extends State<ScheduleSettings> {

@override
Widget build(BuildContext context) => ViewModelBuilder.reactive(
viewModelBuilder: () => ScheduleSettingsViewModel(),
builder: (context, model, child) => SizedBox(
height: MediaQuery.of(context).size.height * 0.50,
child: Column(
children: [
if (widget.showHandle)
Container(
decoration: BoxDecoration(
color: Utils.getColorByBrightness(
context,
AppTheme.lightThemeBackground,
AppTheme.darkThemeBackground),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(40.0),
topRight: Radius.circular(40.0),
)),
child: Center(
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Container(
height: 5,
width: 50,
decoration: const BoxDecoration(
color: Colors.grey,
borderRadius:
BorderRadius.all(Radius.circular(8.0))),
viewModelBuilder: () => ScheduleSettingsViewModel(),
builder: (context, model, child) => ClipRRect(
borderRadius: const BorderRadius.vertical(top: Radius.circular(10)),
child: DraggableScrollableSheet(
maxChildSize: 0.85,
minChildSize: 0.5,
initialChildSize: 0.55,
expand: false,
snap: true,
snapSizes: const [
0.55,
0.85,
],
builder: (context, ScrollController scrollController) {
return Column(children: [
if (widget.showHandle)
Container(
decoration: BoxDecoration(
color: Utils.getColorByBrightness(
context,
AppTheme.lightThemeBackground,
AppTheme.darkThemeBackground),
),
child: Center(
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Container(
height: 5,
width: 50,
decoration: const BoxDecoration(
color: Colors.grey,
borderRadius:
BorderRadius.all(Radius.circular(8.0))),
),
),
),
),
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Utils.getColorByBrightness(
context,
AppTheme.lightThemeBackground,
AppTheme.darkThemeBackground),
),
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Text(
AppIntl.of(context)!.schedule_settings_title,
style: Theme.of(context).textTheme.headline6)),
),
),
),
),
Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Utils.getColorByBrightness(
context,
AppTheme.lightThemeBackground,
AppTheme.darkThemeBackground),
),
child: Center(
child: Padding(
padding: const EdgeInsets.fromLTRB(15, 20, 20, 20),
child: Text(AppIntl.of(context)!.schedule_settings_title,
style: Theme.of(context).textTheme.headline6)),
),
),
Expanded(
child: ListTileTheme(
selectedColor: Theme.of(context).textTheme.bodyText1!.color,
child: ListView(
key: const ValueKey("SettingsScrollingArea"),
children: _buildSettings(
context, model! as ScheduleSettingsViewModel),
),
),
),
],
),
),
);
Expanded(
child: ListTileTheme(
selectedColor:
Theme.of(context).textTheme.bodyText1!.color,
child: Card(
margin: EdgeInsets.zero,
elevation: 0,
shape: const RoundedRectangleBorder(),
color: Colors.transparent,
child: ListView(
controller: scrollController,
key: const ValueKey("SettingsScrollingArea"),
children: _buildSettings(
context, model! as ScheduleSettingsViewModel),
),
),
),
)
]);
}),
));

List<Widget> _buildSettings(
BuildContext context, ScheduleSettingsViewModel model) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: The 4th generation of ÉTSMobile, the main gateway between the Éco
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 4.34.0+1
version: 4.35.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Binary file modified test/ui/widgets/goldenFiles/scheduleSettingsView_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 32 additions & 3 deletions test/ui/widgets/schedule_settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void main() {
expect(
find.byWidgetPredicate((widget) =>
widget is Container &&
widget.decoration is BoxDecoration &&
(widget.decoration! as BoxDecoration).color == Colors.grey),
findsOneWidget,
reason: "The handle should be grey");
Expand Down Expand Up @@ -171,6 +172,20 @@ void main() {
isA<Switch>().having((source) => source.value, 'value', isTrue),
reason:
"the settings says that the showTodayBtn is enabled, the UI should reflet that.");

const screenHeight = 600;

final draggableScrollableSheetFinder =
find.byType(DraggableScrollableSheet);
expect(draggableScrollableSheetFinder, findsOneWidget);

final Size initialSize = tester.getSize(draggableScrollableSheetFinder);
expect(initialSize.height, 0.55 * screenHeight);

await tester.fling(
find.byType(ListView), const Offset(0.0, -4000.0), 400.0);
final Size maxSize = tester.getSize(draggableScrollableSheetFinder);
expect(maxSize.height, 0.85 * screenHeight);
});

testWidgets("Without handle", (WidgetTester tester) async {
Expand All @@ -184,6 +199,7 @@ void main() {
expect(
find.byWidgetPredicate((widget) =>
widget is Container &&
widget.decoration is BoxDecoration &&
(widget.decoration! as BoxDecoration).color == Colors.grey),
findsNothing,
reason: "There should not have a handle.");
Expand Down Expand Up @@ -256,6 +272,20 @@ void main() {
isA<Switch>().having((source) => source.value, 'value', isTrue),
reason:
"the settings says that the showTodayBtn is enabled, the UI should reflet that.");

const screenHeight = 600;

final draggableScrollableSheetFinder =
find.byType(DraggableScrollableSheet);
expect(draggableScrollableSheetFinder, findsOneWidget);

final Size initialSize = tester.getSize(draggableScrollableSheetFinder);
expect(initialSize.height, 0.55 * screenHeight);

await tester.fling(
find.byType(ListView), const Offset(0.0, -4000.0), 400.0);
final Size maxSize = tester.getSize(draggableScrollableSheetFinder);
expect(maxSize.height, 0.85 * screenHeight);
});
});

Expand Down Expand Up @@ -400,9 +430,8 @@ void main() {
ListTile, intl.schedule_settings_show_today_btn_pref,
skipOffstage: false);

expect(find.byType(Switch, skipOffstage: false), findsOneWidget);
// Currently the await tester.tap on a switch in a tile isn't working. Workaround:
(find.byType(Switch, skipOffstage: false).evaluate().single.widget
expect(find.byType(Switch, skipOffstage: false), findsNWidgets(2));
(find.byType(Switch, skipOffstage: false).evaluate().first.widget
as Switch)
.onChanged!(false);

Expand Down

0 comments on commit 79ecf5c

Please sign in to comment.