From 1e14b4290da15f9dff6d22126533d27c829cb5c1 Mon Sep 17 00:00:00 2001 From: Username * Date: Wed, 20 Dec 2023 21:00:24 +0100 Subject: [PATCH] code improvements and use less SizedBox widgets --- .../subject_configs/time_config.dart | 26 +++++++++---------- .../subject_management/subject_screen.dart | 23 +++++++--------- .../widgets/day_view_subject_builder.dart | 18 ++++++------- ...rid_view_overlapping_subjects_builder.dart | 9 +++++-- .../widgets/grid_view_subject_builder.dart | 2 +- lib/components/widgets/list_tile_group.dart | 24 ++++++++--------- lib/components/widgets/navigation_bar.dart | 2 +- lib/main.dart | 2 +- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/lib/components/subject_management/subject_configs/time_config.dart b/lib/components/subject_management/subject_configs/time_config.dart index fad5678..c177936 100644 --- a/lib/components/subject_management/subject_configs/time_config.dart +++ b/lib/components/subject_management/subject_configs/time_config.dart @@ -115,12 +115,11 @@ class TimeConfig extends ConsumerWidget { ), ), ), - const SizedBox( - width: 10, - ), - const Icon(Icons.arrow_forward), - const SizedBox( - width: 10, + const Padding( + padding: EdgeInsets.symmetric( + horizontal: 10, + ), + child: Icon(Icons.arrow_forward), ), ActionChip( side: BorderSide.none, @@ -153,15 +152,14 @@ class TimeConfig extends ConsumerWidget { ), ), ), - if (occupied == true) - const SizedBox( - width: 10, + if (occupied) + const Padding( + padding: EdgeInsets.only(left: 10), + child: Icon( + Icons.cancel, + color: Colors.redAccent, + ), ), - if (occupied == true) - const Icon( - Icons.cancel, - color: Colors.redAccent, - ) ], ); } diff --git a/lib/components/subject_management/subject_screen.dart b/lib/components/subject_management/subject_screen.dart index 2d00ea7..fcfd924 100644 --- a/lib/components/subject_management/subject_screen.dart +++ b/lib/components/subject_management/subject_screen.dart @@ -139,7 +139,7 @@ class SubjectScreen extends HookConsumerWidget { onPressed: () { if (formKey.currentState!.validate()) { if (isSubjectNull) { - if (isOccupied == false) { + if (!isOccupied) { state.addSubject(newSubject); Navigator.pop(context, label.value); } else { @@ -150,7 +150,7 @@ class SubjectScreen extends HookConsumerWidget { ); } } else { - if (isOccupiedExceptSelf == false) { + if (!isOccupiedExceptSelf) { state.updateSubject(subject!, newSubject); Navigator.pop(context, label.value); } else { @@ -220,12 +220,9 @@ class SubjectScreen extends HookConsumerWidget { ), ], ), - const SizedBox( - height: 10, - ), - ColorsConfig(color: color), - const SizedBox( - height: 10, + Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: ColorsConfig(color: color), ), TimeDayRotationWeekConfig( day: day, @@ -234,12 +231,12 @@ class SubjectScreen extends HookConsumerWidget { endTime: endTime, occupied: isSubjectNull ? isOccupied : isOccupiedExceptSelf, ), - const SizedBox( - height: 10, + Padding( + padding: const EdgeInsets.symmetric(vertical: 10), + child: NotesTile( + note: note, + ), ), - NotesTile( - note: note, - ) ], ), ), diff --git a/lib/components/widgets/day_view_subject_builder.dart b/lib/components/widgets/day_view_subject_builder.dart index 5e5b89a..89c4f77 100644 --- a/lib/components/widgets/day_view_subject_builder.dart +++ b/lib/components/widgets/day_view_subject_builder.dart @@ -76,6 +76,7 @@ class DayViewSubjectBuilder extends ConsumerWidget { ), ), ), + // SizedBox is for incase the label is too long const SizedBox( width: 20, ), @@ -123,9 +124,6 @@ class DayViewSubjectBuilder extends ConsumerWidget { size: 19, color: subLabelsColor, ), - const SizedBox( - width: 10, - ), Expanded( child: Text( location.toString(), @@ -143,13 +141,13 @@ class DayViewSubjectBuilder extends ConsumerWidget { if (note != null && note.isNotEmpty) Row( children: [ - Icon( - Icons.sticky_note_2_outlined, - size: 19, - color: subLabelsColor, - ), - const SizedBox( - width: 10, + Padding( + padding: const EdgeInsets.only(right: 10), + child: Icon( + Icons.sticky_note_2_outlined, + size: 19, + color: subLabelsColor, + ), ), Expanded( child: Text( diff --git a/lib/components/widgets/grid_view_overlapping_subjects_builder.dart b/lib/components/widgets/grid_view_overlapping_subjects_builder.dart index eb1bfe9..cba7209 100644 --- a/lib/components/widgets/grid_view_overlapping_subjects_builder.dart +++ b/lib/components/widgets/grid_view_overlapping_subjects_builder.dart @@ -87,7 +87,12 @@ class OverlappingSubjBuilder extends ConsumerWidget { height: (startTimeHour - earlierStartTimeHour) * (tileHeight), ), Padding( - padding: const EdgeInsets.all(outerPadding), + padding: const EdgeInsets.fromLTRB( + outerPadding, + outerPadding, + outerPadding, + outerPadding - 1, + ), child: InkWell( onTap: () { Navigator.push( @@ -116,7 +121,7 @@ class OverlappingSubjBuilder extends ConsumerWidget { width: 0, ), ), - width: ((tileWidth / 2) - .75) - (outerPadding * 2), + width: ((tileWidth / 2) - .75) - (outerPadding * 2.25), height: (((endTimeHour - startTimeHour) * (tileHeight)) - 1) - (outerPadding * 2), diff --git a/lib/components/widgets/grid_view_subject_builder.dart b/lib/components/widgets/grid_view_subject_builder.dart index 9043e94..ed76096 100644 --- a/lib/components/widgets/grid_view_subject_builder.dart +++ b/lib/components/widgets/grid_view_subject_builder.dart @@ -106,7 +106,7 @@ class SubjectBuilder extends ConsumerWidget { height: 5, ), if ((location != null)) - if (hideLocation == false) + if (!hideLocation) if (!hideTransparentSubjects) Text( location.toString(), diff --git a/lib/components/widgets/list_tile_group.dart b/lib/components/widgets/list_tile_group.dart index 10396da..f2bed89 100644 --- a/lib/components/widgets/list_tile_group.dart +++ b/lib/components/widgets/list_tile_group.dart @@ -80,18 +80,18 @@ class ListItem extends StatelessWidget { Widget build(BuildContext context) { return Column( children: [ - ListTile( - title: title, - subtitle: subtitle, - leading: leading, - onTap: () { - onTap; - }, - shape: shape, - tileColor: Theme.of(context).colorScheme.surfaceVariant, - ), - const SizedBox( - height: 2, + Padding( + padding: const EdgeInsets.only(bottom: 2), + child: ListTile( + title: title, + subtitle: subtitle, + leading: leading, + onTap: () { + onTap; + }, + shape: shape, + tileColor: Theme.of(context).colorScheme.surfaceVariant, + ), ), ], ); diff --git a/lib/components/widgets/navigation_bar.dart b/lib/components/widgets/navigation_bar.dart index c4e8736..6df3a18 100644 --- a/lib/components/widgets/navigation_bar.dart +++ b/lib/components/widgets/navigation_bar.dart @@ -62,7 +62,7 @@ class Navigation extends HookConsumerWidget { case 0: return const TimetableScreen(); case 1: - return SettingsScreen(); + return const SettingsScreen(); default: return const TimetableScreen(); } diff --git a/lib/main.dart b/lib/main.dart index d989ee5..1d44fdb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -59,7 +59,7 @@ class Timetable extends ConsumerWidget { ), useMaterial3: true, ), - home: Navigation(), + home: const Navigation(), ); }, );