simplified code across the app and consolidated duplicated helpers
This commit is contained in:
+16
-32
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -145,19 +146,17 @@ class AppRoutes {
|
||||
/// the selected element (or null if dismissed). The timetable view renders
|
||||
/// the chosen plan inline. Gated behind the `viewForeignTimetables`
|
||||
/// capability at the call site.
|
||||
static Future<TimetableElementRef?> openElementPicker(
|
||||
static Future<TimetableElementRef?> openElementPicker(BuildContext context) =>
|
||||
_pushForResult(context, const ElementPickerPage());
|
||||
|
||||
// pushScreen casts its internal MaterialPageRoute to `Route<T>`, which blows
|
||||
// up for a concrete (record) T — so push untyped (T = dynamic, like every
|
||||
// other caller) and cast the popped result ourselves.
|
||||
static Future<T?> _pushForResult<T>(
|
||||
BuildContext context,
|
||||
) async {
|
||||
// pushScreen casts its internal MaterialPageRoute to `Route<T>`, which
|
||||
// blows up for a concrete (record) T — so push untyped (T = dynamic, like
|
||||
// every other caller) and cast the popped result ourselves.
|
||||
final result = await pushScreen(
|
||||
context,
|
||||
withNavBar: false,
|
||||
screen: const ElementPickerPage(),
|
||||
);
|
||||
return result as TimetableElementRef?;
|
||||
}
|
||||
Widget screen,
|
||||
) async =>
|
||||
(await pushScreen(context, withNavBar: false, screen: screen)) as T?;
|
||||
|
||||
/// Opens the user/group picker for sharing a file and resolves to the chosen
|
||||
/// recipient (or null if dismissed). Which kinds are offered is gated by the
|
||||
@@ -166,19 +165,10 @@ class AppRoutes {
|
||||
BuildContext context, {
|
||||
required bool allowUsers,
|
||||
required bool allowGroups,
|
||||
}) async {
|
||||
// Push untyped (T = dynamic) and cast the popped result ourselves —
|
||||
// pushScreen can't carry a concrete non-Widget T (see openElementPicker).
|
||||
final result = await pushScreen(
|
||||
context,
|
||||
withNavBar: false,
|
||||
screen: ShareePickerPage(
|
||||
allowUsers: allowUsers,
|
||||
allowGroups: allowGroups,
|
||||
),
|
||||
);
|
||||
return result as ShareeRef?;
|
||||
}
|
||||
}) => _pushForResult(
|
||||
context,
|
||||
ShareePickerPage(allowUsers: allowUsers, allowGroups: allowGroups),
|
||||
);
|
||||
|
||||
static void openMarianumMessage(
|
||||
BuildContext context,
|
||||
@@ -452,13 +442,7 @@ class AppRoutes {
|
||||
static GetRoomResponseObject? _findRoomByToken(
|
||||
GetRoomResponse? rooms,
|
||||
String token,
|
||||
) {
|
||||
if (rooms == null) return null;
|
||||
for (final room in rooms.data) {
|
||||
if (room.token == token) return room;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
) => rooms?.data.firstWhereOrNull((room) => room.token == token);
|
||||
|
||||
/// Pushes a module from the "Mehr" tab list. Modules already in the bottom
|
||||
/// bar are switched to via [goToTab] instead.
|
||||
|
||||
Reference in New Issue
Block a user