Browse Source

neon: enable apps to specify go_routes

pull/466/head
Nikolas Rimikis 2 years ago
parent
commit
d2893ff239
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 29
      packages/neon/neon/lib/src/models/app_implementation.dart
  2. 16
      packages/neon/neon/lib/src/utils/app_route.dart
  3. 1
      packages/neon/neon/lib/utils.dart

29
packages/neon/neon/lib/src/models/app_implementation.dart

@ -1,6 +1,7 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/blocs/accounts.dart';
@ -68,6 +69,34 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
);
}
/// Main branch displayed in the home page.
///
/// There's usually no need to override this.
StatefulShellBranch get mainBranch => StatefulShellBranch(
routes: [
route,
],
);
/// Route for the app.
///
/// All pages of the app must be specified as subroutes.
/// If this is not [GoRoute] an inital route name must be specified by overriding [initialRouteName].
RouteBase get route => throw UnimplementedError();
/// Name of the initial route for this app.
///
/// Subclasses that don't provide a [GoRoute] for [route] must override this.
String get initialRouteName {
final route = this.route;
if (route is GoRoute && route.name != null) {
return route.name!;
}
throw FlutterError('No name for the initial route provided.');
}
Widget buildIcon({
final Size size = const Size.square(32),
final Color? color,

16
packages/neon/neon/lib/src/utils/app_route.dart

@ -0,0 +1,16 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
/// [RouteData] for the initial page of an app.
///
/// Subclasses must override one of [build] or [redirect].
abstract class NeonAppRoute extends GoRouteData {
const NeonAppRoute();
@override
Page<void> buildPage(final BuildContext context, final GoRouterState state) => NoTransitionPage(
child: build(context, state),
);
}
const appsRoutePrefix = '/apps/';

1
packages/neon/neon/lib/utils.dart

@ -1,3 +1,4 @@
export 'package:neon/src/utils/app_route.dart';
export 'package:neon/src/utils/confirmation_dialog.dart';
export 'package:neon/src/utils/exceptions.dart';
export 'package:neon/src/utils/hex_color.dart';

Loading…
Cancel
Save