Skip to content

Commit

Permalink
Fix app errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jsondergaard committed Nov 15, 2023
1 parent 4f898ad commit 2bf30e0
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 270 deletions.
2 changes: 1 addition & 1 deletion lib/blocs/activity_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActivityBloc extends BlocBase {

/// Stream for updated ActivityModel.
Stream<ActivityModel> get activityModelStream => _activityModelStream.stream;
late StreamSubscription<ActivityModel>?
StreamSubscription<ActivityModel>?
_subscription; // ignore: cancel_subscriptions
/// rx_dart.BehaviorSubject for the updated ActivityModel.
final rx_dart.BehaviorSubject<ActivityModel> _activityModelStream =
Expand Down
8 changes: 4 additions & 4 deletions lib/blocs/copy_weekplan_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CopyWeekplanBloc extends ChooseCitizenBloc {
final Completer<bool> callCompleter = Completer<bool>();
_api.week
.update(
user.id!, weekModel.weekYear!, weekModel.weekNumber!, weekModel)
user.id!, weekModel.weekYear, weekModel.weekNumber, weekModel)
.take(1)
.listen((WeekModel weekModel) {
callCompleter.complete(true);
Expand All @@ -55,7 +55,7 @@ class CopyWeekplanBloc extends ChooseCitizenBloc {
bool daysAreEmpty = true;

final WeekModel response = await _api.week
.get(user.id!, weekModel.weekYear!, weekModel.weekNumber!)
.get(user.id!, weekModel.weekYear, weekModel.weekNumber)
.first;

if (response.days == null) {
Expand All @@ -69,8 +69,8 @@ class CopyWeekplanBloc extends ChooseCitizenBloc {
///Checks whether the name of the week model is different from the default
/// created when no week exists
if (daysAreEmpty) {
final int weekYear = weekModel.weekYear!;
final int weekNumber = weekModel.weekNumber!;
final int weekYear = weekModel.weekYear;
final int weekNumber = weekModel.weekNumber;
daysAreEmpty = response.name!.compareTo('$weekYear - $weekNumber') == 0;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/blocs/edit_weekplan_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class EditWeekplanBloc extends NewWeekplanBloc {

final bool hasExistingMatch = await hasExisitingMatchingWeekplan(
existingWeekPlans: selectorBloc.weekNameModels,
year: newWeekModel.weekYear!,
weekNumber: newWeekModel.weekNumber!);
year: newWeekModel.weekYear,
weekNumber: newWeekModel.weekNumber);

// If there is a match, ask the user if we should overwrite.
if (hasExistingMatch) {
doOverwrite = await displayOverwriteDialog(
screenContext!, newWeekModel.weekNumber!, newWeekModel.weekYear!);
screenContext!, newWeekModel.weekNumber, newWeekModel.weekYear);
}

// Here we delete the old week plan (we had to do this because of the way
Expand All @@ -69,8 +69,8 @@ class EditWeekplanBloc extends NewWeekplanBloc {

if (doOverwrite) {
weekApi.week
.update(super.weekUser!.id!, newWeekModel.weekYear!,
newWeekModel.weekNumber!, newWeekModel)
.update(super.weekUser!.id!, newWeekModel.weekYear,
newWeekModel.weekNumber, newWeekModel)
.take(1)
.listen(updateCompleter.complete);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/new_weekplan_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class NewWeekplanBloc extends BlocBase {
final Completer<WeekModel> saveCompleter = Completer<WeekModel>();
if (doOverwrite) {
weekApi.week
.update(weekUser!.id!, _weekModel.weekYear!, _weekModel.weekNumber!,
.update(weekUser!.id!, _weekModel.weekYear, _weekModel.weekNumber,
_weekModel)
.take(1)
.listen(saveCompleter.complete);
Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/timer_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TimerBloc extends BlocBase {
/// stream for checking if the timer is running
Stream<TimerRunningMode> get timerRunningMode =>
_timerRunningModeStream.stream;
late StreamSubscription<TimerRunningMode>?
StreamSubscription<TimerRunningMode>?
_subscription; // ignore: cancel_subscriptions

/// Stream for checking if the timer is instantiated.
Expand Down
14 changes: 7 additions & 7 deletions lib/blocs/weekplan_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class WeekplanBloc extends BlocBase {
/// Sink to set the currently chosen week
Future<void> getWeek(WeekModel week, DisplayNameModel user) async {
_api.week
.get(user.id!, week.weekYear!, week.weekNumber!)
.get(user.id!, week.weekYear, week.weekNumber)
.listen((WeekModel loadedWeek) {
_week = loadedWeek;
_userWeek.add(UserWeekModel(loadedWeek, user));
Expand All @@ -73,7 +73,7 @@ class WeekplanBloc extends BlocBase {
/// Get the current week fresh from the api
Future<void> loadWeek(DisplayNameModel user) async {
_api.week
.get(user.id!, _week.weekYear!, _week.weekNumber!)
.get(user.id!, _week.weekYear, _week.weekNumber)
.listen((WeekModel loadedWeek) {
_userWeek.add(UserWeekModel(loadedWeek, user));
_week = loadedWeek;
Expand Down Expand Up @@ -197,7 +197,7 @@ class WeekplanBloc extends BlocBase {
}

_api.week
.update(user.id!, week.weekYear!, week.weekNumber!, week)
.update(user.id!, week.weekYear, week.weekNumber, week)
.listen((WeekModel newWeek) {
_userWeek.add(UserWeekModel(newWeek, user));
});
Expand Down Expand Up @@ -264,8 +264,8 @@ class WeekplanBloc extends BlocBase {
final Completer<void> completer = Completer<void>();
final DisplayNameModel user = _userWeek.value.user;
_api.activity
.add(activity, user.id!, _week.name!, _week.weekYear!,
_week.weekNumber!, _week.days![day].day!)
.add(activity, user.id!, _week.name!, _week.weekYear, _week.weekNumber,
_week.days![day].day!)
.listen((ActivityModel ac) {
_week.days![day].activities!.add(ac);
updateWeekdays(<WeekdayModel>[_week.days![day]])
Expand Down Expand Up @@ -339,7 +339,7 @@ class WeekplanBloc extends BlocBase {
Future<void> getWeekday(Weekday day) async {
final DisplayNameModel user = _userWeek.value.user;
_api.week
.getDay(user.id!, _week.weekYear!, _week.weekNumber!, day)
.getDay(user.id!, _week.weekYear, _week.weekNumber, day)
.listen((WeekdayModel newDay) {
_weekDayStreams[newDay.day!.index - _firstDay].add(newDay);
}).onError((Object error) {
Expand All @@ -354,7 +354,7 @@ class WeekplanBloc extends BlocBase {
final DisplayNameModel user = _userWeek.value.user;
for (WeekdayModel day in days) {
_api.week
.updateDay(user.id!, _week.weekYear!, _week.weekNumber!, day)
.updateDay(user.id!, _week.weekYear, _week.weekNumber, day)
.listen((WeekdayModel newDay) {
_weekDayStreams[newDay.day!.index - _firstDay].add(newDay);
_week.days![newDay.day!.index] = newDay;
Expand Down
16 changes: 8 additions & 8 deletions lib/blocs/weekplan_selector_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ class WeekplansBloc extends BlocBase {
return -1;
}
if (a.weekYear == b.weekYear) {
return a.weekNumber!.compareTo(b.weekNumber!);
return a.weekNumber.compareTo(b.weekNumber);
} else {
return a.weekYear!.compareTo(b.weekYear!);
return a.weekYear.compareTo(b.weekYear);
}
});
return list;
Expand All @@ -216,9 +216,9 @@ class WeekplansBloc extends BlocBase {
List<WeekModel> _sortOldWeekPlans(List<WeekModel> list) {
list.toList().sort((WeekModel a, WeekModel b) {
if (a.weekYear == b.weekYear) {
return b.weekNumber!.compareTo(a.weekNumber!);
return b.weekNumber.compareTo(a.weekNumber);
} else {
return b.weekYear!.compareTo(a.weekYear!);
return b.weekYear.compareTo(a.weekYear);
}
});
return list;
Expand Down Expand Up @@ -268,7 +268,7 @@ class WeekplansBloc extends BlocBase {
// Updates the weekplan in the database
for (WeekModel weekModel in _markedWeekModels.value) {
_api.week
.delete(_user.id!, weekModel.weekYear!, weekModel.weekNumber!)
.delete(_user.id!, weekModel.weekYear, weekModel.weekNumber)
.listen((bool deleted) {
if (deleted) {
// Checks if its an old or upcoming weekplan
Expand Down Expand Up @@ -304,7 +304,7 @@ class WeekplansBloc extends BlocBase {
/// This method deletes the given week model from the database
void deleteWeek(List<WeekModel> weekModels, WeekModel weekModel) {
_api.week
.delete(_user.id!, weekModel.weekYear!, weekModel.weekNumber!)
.delete(_user.id!, weekModel.weekYear, weekModel.weekNumber)
.listen((bool deleted) {
if (deleted) {
weekModels.remove(weekModel);
Expand All @@ -331,7 +331,7 @@ class WeekplansBloc extends BlocBase {

final Completer<WeekModel> completer = Completer<WeekModel>();
_api.week
.get(_user.id!, marked.weekYear!, marked.weekNumber!)
.get(_user.id!, marked.weekYear, marked.weekNumber)
.listen((WeekModel weekModel) => completer.complete(weekModel));

return completer.future;
Expand All @@ -343,7 +343,7 @@ class WeekplansBloc extends BlocBase {
for (WeekModel weekModel in _markedWeekModels.value) {
final Completer<WeekModel> completer = Completer<WeekModel>();
_api.week
.get(_user.id!, weekModel.weekYear!, weekModel.weekNumber!)
.get(_user.id!, weekModel.weekYear, weekModel.weekNumber)
.listen((WeekModel weekModel) => completer.complete(weekModel));
weekList.add(await completer.future);
}
Expand Down
25 changes: 12 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:weekplanner/screens/login_screen.dart';
import 'package:weekplanner/widgets/giraf_notify_dialog.dart';

final Api _api = di.get<Api>();
final AuthBloc _authBloc = di.get<AuthBloc>();

void main() {
// Register all dependencies for injector
Expand Down Expand Up @@ -62,18 +61,18 @@ void _runApp() {

if (loggedIn) {
// Show screen dependent on logged in role
switch (_authBloc.loggedInUser.role) {
// case Role.Citizen:
// return WeekplanSelectorScreen(
// DisplayNameModel(
// displayName: _authBloc!.loggedInUser.displayName,
// role: describeEnum(_authBloc!.loggedInUser.role!),
// id: _authBloc!.loggedInUser.id,
// ),
// );
default:
return ChooseCitizenScreen();
}
// switch (_authBloc.loggedInUser.role ?? 'lol') {
// // case Role.Citizen:
// // return WeekplanSelectorScreen(
// // DisplayNameModel(
// // displayName: _authBloc!.loggedInUser.displayName,
// // role: describeEnum(_authBloc!.loggedInUser.role!),
// // id: _authBloc!.loggedInUser.id,
// // ),
// // );
// default:
return ChooseCitizenScreen();
// }
} else {
// Not loggedIn pop context to login screen.
Routes().goHome(context);
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/copy_resolve_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class CopyResolveScreen extends StatelessWidget {
if (numberOfConflicts > 0) {
toCopy = await _displayConflictDialog(
context,
newWeekModel.weekNumber!,
newWeekModel.weekYear!,
newWeekModel.weekNumber,
newWeekModel.weekYear,
numberOfConflicts,
currentUser);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/screens/show_activity_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,18 @@ class ShowActivityScreen extends StatelessWidget {
stream: _authBloc.mode,
builder: (BuildContext context, AsyncSnapshot<WeekplanMode> snapshot) {
return buildScreenFromOrientation(
orientation, context, snapshot.data!);
orientation, context, snapshot.data);
});
}

/// Build the activity screens in a row or column
/// depending on the orientation of the device.
Scaffold buildScreenFromOrientation(
Orientation orientation, BuildContext context, WeekplanMode mode) {
Orientation orientation, BuildContext context, WeekplanMode? mode) {
late Widget childContainer;

mode ??= WeekplanMode.citizen;

try {
if (orientation == Orientation.portrait) {
childContainer = Column(
Expand Down
34 changes: 13 additions & 21 deletions lib/screens/weekplan_selector_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,19 @@ class _WeekplanSelectorScreenState extends State<WeekplanSelectorScreen> {
);
})),
Container(
child: weekplan.weekNumber == null
? null
: Expanded(child: LayoutBuilder(builder:
(BuildContext context,
BoxConstraints constraints) {
return AutoSizeText(
'Uge: ${weekplan.weekNumber} '
'År: ${weekplan.weekYear}',
key: const Key('weekYear'),
style:
const TextStyle(fontSize: GirafFont.small),
maxLines: 1,
minFontSize: 14,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
);
})),
child: Expanded(child: LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
return AutoSizeText(
'Uge: ${weekplan.weekNumber} '
'År: ${weekplan.weekYear}',
key: const Key('weekYear'),
style: const TextStyle(fontSize: GirafFont.small),
maxLines: 1,
minFontSize: 14,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
);
})),
)
],
)),
Expand Down Expand Up @@ -502,10 +498,6 @@ class _WeekplanSelectorScreenState extends State<WeekplanSelectorScreen> {

/// Builds dialog box to confirm/cancel deletion
Future<Center?> _buildDeletionDialog(BuildContext context) {
// if (widget._weekBloc.getNumberOfMarkedWeekModels() == 0) {
// return null;
// } // FIXME: Handle this

return showDialog<Center>(
barrierDismissible: false,
context: context,
Expand Down
Loading

0 comments on commit 2bf30e0

Please sign in to comment.