feat: add Flutter mobile clients and staff delivery API
This commit is contained in:
140
apps/service_app/lib/app/router.dart
Normal file
140
apps/service_app/lib/app/router.dart
Normal file
@@ -0,0 +1,140 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../ui/features/auth/login_page.dart';
|
||||
import '../ui/features/evidence/evidence_page.dart';
|
||||
import '../ui/features/preflight/preflight_page.dart';
|
||||
import '../ui/features/profile/profile_page.dart';
|
||||
import '../ui/features/work/work_detail_page.dart';
|
||||
import '../ui/features/work/work_list_page.dart';
|
||||
import 'dependencies.dart';
|
||||
|
||||
GoRouter createRouter(AppDependencies dependencies) => GoRouter(
|
||||
initialLocation: '/preflight',
|
||||
refreshListenable: dependencies.session,
|
||||
redirect: (context, state) {
|
||||
final login = state.matchedLocation == '/login';
|
||||
if (!dependencies.session.isAuthenticated && !login) return '/login';
|
||||
if (dependencies.session.isAuthenticated && login) return '/preflight';
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
builder: (context, state) => LoginPage(session: dependencies.session),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/preflight',
|
||||
builder: (context, state) => PreflightPage(
|
||||
session: dependencies.session,
|
||||
repository: dependencies.repository,
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/tasks/:identity',
|
||||
builder: (context, state) => WorkDetailPage(
|
||||
session: dependencies.session,
|
||||
repository: dependencies.repository,
|
||||
drafts: dependencies.drafts,
|
||||
identity: state.pathParameters['identity']!,
|
||||
),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'evidence',
|
||||
builder: (context, state) => EvidencePage(
|
||||
session: dependencies.session,
|
||||
repository: dependencies.repository,
|
||||
drafts: dependencies.drafts,
|
||||
taskIdentity: state.pathParameters['identity']!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
StatefulShellRoute.indexedStack(
|
||||
builder: (context, state, shell) => _ServiceShell(
|
||||
navigationShell: shell,
|
||||
roleCode: dependencies.session.roleCode,
|
||||
),
|
||||
branches: [
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/work',
|
||||
builder: (context, state) => WorkListPage(
|
||||
session: dependencies.session,
|
||||
repository: dependencies.repository,
|
||||
completed: false,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/records',
|
||||
builder: (context, state) => WorkListPage(
|
||||
session: dependencies.session,
|
||||
repository: dependencies.repository,
|
||||
completed: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/me',
|
||||
builder: (context, state) => ProfilePage(
|
||||
session: dependencies.session,
|
||||
repository: dependencies.repository,
|
||||
drafts: dependencies.drafts,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
class _ServiceShell extends StatelessWidget {
|
||||
const _ServiceShell({required this.navigationShell, required this.roleCode});
|
||||
|
||||
final StatefulNavigationShell navigationShell;
|
||||
final String roleCode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
body: navigationShell,
|
||||
bottomNavigationBar: NavigationBar(
|
||||
selectedIndex: navigationShell.currentIndex,
|
||||
onDestinationSelected: (index) => navigationShell.goBranch(
|
||||
index,
|
||||
initialLocation: index == navigationShell.currentIndex,
|
||||
),
|
||||
destinations: [
|
||||
NavigationDestination(
|
||||
icon: Icon(
|
||||
roleCode == 'delivery' ? Icons.local_shipping_outlined : Icons.assignment_outlined,
|
||||
),
|
||||
selectedIcon: Icon(roleCode == 'delivery' ? Icons.local_shipping : Icons.assignment),
|
||||
label: roleCode == 'delivery'
|
||||
? '配送'
|
||||
: roleCode == 'operations'
|
||||
? '安检'
|
||||
: '工单',
|
||||
),
|
||||
const NavigationDestination(
|
||||
icon: Icon(Icons.history),
|
||||
selectedIcon: Icon(Icons.history_toggle_off),
|
||||
label: '记录',
|
||||
),
|
||||
const NavigationDestination(
|
||||
icon: Icon(Icons.person_outline),
|
||||
selectedIcon: Icon(Icons.person),
|
||||
label: '我的',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user