Apply a Material 3 seed-green palette and rounded components across the home, inventory, quick-add, quantity picker and variety-detail screens. The full-screen photo viewer can now set any photo as the cover (via attachment sort order) and delete after confirmation. Lot forms and packaging surface as choice chips. Extract About out of Settings into its own screen (app version via package_info_plus, website link). Add es/en strings for the new lot types, presentation, home tagline and About. Update Seedees v2 mockups.
100 lines
3.3 KiB
Dart
100 lines
3.3 KiB
Dart
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'data/species_repository.dart';
|
|
import 'data/variety_repository.dart';
|
|
import 'i18n/strings.g.dart';
|
|
import 'state/inventory_cubit.dart';
|
|
import 'state/variety_detail_cubit.dart';
|
|
import 'ui/about_screen.dart';
|
|
import 'ui/home_screen.dart';
|
|
import 'ui/inventory_list_screen.dart';
|
|
import 'ui/settings_screen.dart';
|
|
import 'ui/theme.dart';
|
|
import 'ui/variety_detail_screen.dart';
|
|
|
|
/// Root widget. Provides the repositories to the tree and wires go_router:
|
|
/// `/` is the home menu, `/inventory` the list, `/variety/:id` the item detail.
|
|
class TaneApp extends StatelessWidget {
|
|
TaneApp({required this.repository, required this.species, super.key})
|
|
: _router = _buildRouter(repository);
|
|
|
|
final VarietyRepository repository;
|
|
final SpeciesRepository species;
|
|
final GoRouter _router;
|
|
|
|
static GoRouter _buildRouter(VarietyRepository repository) {
|
|
return GoRouter(
|
|
routes: [
|
|
GoRoute(path: '/', builder: (context, state) => const HomeScreen()),
|
|
GoRoute(
|
|
path: '/settings',
|
|
builder: (context, state) => const SettingsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/about',
|
|
builder: (context, state) => const AboutScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/inventory',
|
|
builder: (context, state) => BlocProvider(
|
|
create: (_) => InventoryCubit(repository),
|
|
child: const InventoryListScreen(),
|
|
),
|
|
),
|
|
GoRoute(
|
|
path: '/variety/:id',
|
|
builder: (context, state) => BlocProvider(
|
|
create: (_) =>
|
|
VarietyDetailCubit(repository, state.pathParameters['id']!),
|
|
child: const VarietyDetailScreen(),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiRepositoryProvider(
|
|
providers: [
|
|
RepositoryProvider.value(value: repository),
|
|
RepositoryProvider.value(value: species),
|
|
],
|
|
child: MaterialApp.router(
|
|
onGenerateTitle: (context) => context.t.app.title,
|
|
debugShowCheckedModeBanner: false,
|
|
theme: buildTaneTheme(),
|
|
// Let scrollables & PageViews be dragged with a mouse/trackpad on
|
|
// desktop (Flutter disables that by default), so the photo carousel and
|
|
// lists swipe there too.
|
|
scrollBehavior: const _DragScrollBehavior(),
|
|
locale: TranslationProvider.of(context).flutterLocale,
|
|
supportedLocales: AppLocaleUtils.supportedLocales,
|
|
localizationsDelegates: const [
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
routerConfig: _router,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Enables mouse/trackpad drag scrolling (off by default on desktop) so the
|
|
/// photo carousel and lists can be swiped with a pointer.
|
|
class _DragScrollBehavior extends MaterialScrollBehavior {
|
|
const _DragScrollBehavior();
|
|
|
|
@override
|
|
Set<PointerDeviceKind> get dragDevices => {
|
|
PointerDeviceKind.touch,
|
|
PointerDeviceKind.mouse,
|
|
PointerDeviceKind.trackpad,
|
|
PointerDeviceKind.stylus,
|
|
};
|
|
}
|