mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-15 23:49:30 +00:00
routes
This commit is contained in:
parent
ebc14a0448
commit
f8597f7430
13 changed files with 509 additions and 33 deletions
34
lib/router/constants.dart
Normal file
34
lib/router/constants.dart
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// to store names of routes
|
||||
|
||||
part of 'router.dart';
|
||||
|
||||
class Routes {
|
||||
static const home = 'home';
|
||||
static const onboarding = 'onboarding';
|
||||
static const library = _SimpleRoute(
|
||||
pathName: 'library',
|
||||
pathParamName: 'libraryId',
|
||||
name: 'library',
|
||||
);
|
||||
static const libraryItem = _SimpleRoute(
|
||||
pathName: 'item',
|
||||
pathParamName: 'itemId',
|
||||
name: 'libraryItem',
|
||||
);
|
||||
}
|
||||
|
||||
// a class to store path
|
||||
|
||||
class _SimpleRoute {
|
||||
const _SimpleRoute({
|
||||
required this.pathName,
|
||||
required this.pathParamName,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
final String pathName;
|
||||
final String pathParamName;
|
||||
final String name;
|
||||
|
||||
String get path => '/$pathName/:$pathParamName';
|
||||
}
|
||||
23
lib/router/models/library_item_extras.dart
Normal file
23
lib/router/models/library_item_extras.dart
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// a freezed class to store the settings of the app
|
||||
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:shelfsdk/audiobookshelf_api.dart';
|
||||
|
||||
part 'library_item_extras.freezed.dart';
|
||||
part 'library_item_extras.g.dart';
|
||||
|
||||
/// any extras when navigating to a library item
|
||||
///
|
||||
/// [shelfId] is the id of the shelf that the item was on before navigating to the item
|
||||
/// [book] is the book that the item represents
|
||||
/// [heroTagSuffix] is the suffix to use for the hero tag to avoid conflicts
|
||||
@freezed
|
||||
class LibraryItemExtras with _$LibraryItemExtras {
|
||||
const factory LibraryItemExtras({
|
||||
BookMinified? book,
|
||||
String? heroTagSuffix,
|
||||
}) = _LibraryItemExtras;
|
||||
|
||||
factory LibraryItemExtras.fromJson(Map<String, dynamic> json) =>
|
||||
_$LibraryItemExtrasFromJson(json);
|
||||
}
|
||||
171
lib/router/models/library_item_extras.freezed.dart
Normal file
171
lib/router/models/library_item_extras.freezed.dart
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'library_item_extras.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
LibraryItemExtras _$LibraryItemExtrasFromJson(Map<String, dynamic> json) {
|
||||
return _LibraryItemExtras.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$LibraryItemExtras {
|
||||
BookMinified? get book => throw _privateConstructorUsedError;
|
||||
String? get heroTagSuffix => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$LibraryItemExtrasCopyWith<LibraryItemExtras> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $LibraryItemExtrasCopyWith<$Res> {
|
||||
factory $LibraryItemExtrasCopyWith(
|
||||
LibraryItemExtras value, $Res Function(LibraryItemExtras) then) =
|
||||
_$LibraryItemExtrasCopyWithImpl<$Res, LibraryItemExtras>;
|
||||
@useResult
|
||||
$Res call({BookMinified? book, String? heroTagSuffix});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$LibraryItemExtrasCopyWithImpl<$Res, $Val extends LibraryItemExtras>
|
||||
implements $LibraryItemExtrasCopyWith<$Res> {
|
||||
_$LibraryItemExtrasCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? book = freezed,
|
||||
Object? heroTagSuffix = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
book: freezed == book
|
||||
? _value.book
|
||||
: book // ignore: cast_nullable_to_non_nullable
|
||||
as BookMinified?,
|
||||
heroTagSuffix: freezed == heroTagSuffix
|
||||
? _value.heroTagSuffix
|
||||
: heroTagSuffix // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$LibraryItemExtrasImplCopyWith<$Res>
|
||||
implements $LibraryItemExtrasCopyWith<$Res> {
|
||||
factory _$$LibraryItemExtrasImplCopyWith(_$LibraryItemExtrasImpl value,
|
||||
$Res Function(_$LibraryItemExtrasImpl) then) =
|
||||
__$$LibraryItemExtrasImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({BookMinified? book, String? heroTagSuffix});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$LibraryItemExtrasImplCopyWithImpl<$Res>
|
||||
extends _$LibraryItemExtrasCopyWithImpl<$Res, _$LibraryItemExtrasImpl>
|
||||
implements _$$LibraryItemExtrasImplCopyWith<$Res> {
|
||||
__$$LibraryItemExtrasImplCopyWithImpl(_$LibraryItemExtrasImpl _value,
|
||||
$Res Function(_$LibraryItemExtrasImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? book = freezed,
|
||||
Object? heroTagSuffix = freezed,
|
||||
}) {
|
||||
return _then(_$LibraryItemExtrasImpl(
|
||||
book: freezed == book
|
||||
? _value.book
|
||||
: book // ignore: cast_nullable_to_non_nullable
|
||||
as BookMinified?,
|
||||
heroTagSuffix: freezed == heroTagSuffix
|
||||
? _value.heroTagSuffix
|
||||
: heroTagSuffix // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$LibraryItemExtrasImpl implements _LibraryItemExtras {
|
||||
const _$LibraryItemExtrasImpl({this.book, this.heroTagSuffix});
|
||||
|
||||
factory _$LibraryItemExtrasImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$LibraryItemExtrasImplFromJson(json);
|
||||
|
||||
@override
|
||||
final BookMinified? book;
|
||||
@override
|
||||
final String? heroTagSuffix;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'LibraryItemExtras(book: $book, heroTagSuffix: $heroTagSuffix)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$LibraryItemExtrasImpl &&
|
||||
(identical(other.book, book) || other.book == book) &&
|
||||
(identical(other.heroTagSuffix, heroTagSuffix) ||
|
||||
other.heroTagSuffix == heroTagSuffix));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, book, heroTagSuffix);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$LibraryItemExtrasImplCopyWith<_$LibraryItemExtrasImpl> get copyWith =>
|
||||
__$$LibraryItemExtrasImplCopyWithImpl<_$LibraryItemExtrasImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$LibraryItemExtrasImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _LibraryItemExtras implements LibraryItemExtras {
|
||||
const factory _LibraryItemExtras(
|
||||
{final BookMinified? book,
|
||||
final String? heroTagSuffix}) = _$LibraryItemExtrasImpl;
|
||||
|
||||
factory _LibraryItemExtras.fromJson(Map<String, dynamic> json) =
|
||||
_$LibraryItemExtrasImpl.fromJson;
|
||||
|
||||
@override
|
||||
BookMinified? get book;
|
||||
@override
|
||||
String? get heroTagSuffix;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$LibraryItemExtrasImplCopyWith<_$LibraryItemExtrasImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
23
lib/router/models/library_item_extras.g.dart
Normal file
23
lib/router/models/library_item_extras.g.dart
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'library_item_extras.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$LibraryItemExtrasImpl _$$LibraryItemExtrasImplFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$LibraryItemExtrasImpl(
|
||||
book: json['book'] == null
|
||||
? null
|
||||
: BookMinified.fromJson(json['book'] as Map<String, dynamic>),
|
||||
heroTagSuffix: json['heroTagSuffix'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$LibraryItemExtrasImplToJson(
|
||||
_$LibraryItemExtrasImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'book': instance.book,
|
||||
'heroTagSuffix': instance.heroTagSuffix,
|
||||
};
|
||||
52
lib/router/router.dart
Normal file
52
lib/router/router.dart
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import 'package:go_router/go_router.dart';
|
||||
import 'package:whispering_pages/pages/home_page.dart';
|
||||
import 'package:whispering_pages/pages/library_item_page.dart';
|
||||
import 'package:whispering_pages/pages/library_page.dart';
|
||||
import 'package:whispering_pages/pages/onboarding/onboarding.dart';
|
||||
|
||||
part 'constants.dart';
|
||||
|
||||
// GoRouter configuration
|
||||
class MyAppRouter {
|
||||
const MyAppRouter({required this.needOnboarding});
|
||||
final bool needOnboarding;
|
||||
// some static strings for named routes
|
||||
|
||||
GoRouter get config => GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
name: Routes.onboarding,
|
||||
builder: (context, state) => const OnboardingPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/',
|
||||
name: Routes.home,
|
||||
builder: (context, state) => const HomePage(),
|
||||
),
|
||||
// /library/:libraryId
|
||||
GoRoute(
|
||||
path: Routes.library.path,
|
||||
name: Routes.library.name,
|
||||
builder: (context, state) => LibraryPage(
|
||||
libraryId: state.pathParameters[Routes.library.pathParamName]!,
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.libraryItem.path,
|
||||
name: Routes.libraryItem.name,
|
||||
builder: (context, state) {
|
||||
final itemId =
|
||||
state.pathParameters[Routes.libraryItem.pathParamName]!;
|
||||
return LibraryItemPage(itemId: itemId, extra: state.extra);
|
||||
},
|
||||
),
|
||||
],
|
||||
redirect: (context, state) {
|
||||
if (needOnboarding) {
|
||||
return context.namedLocation(Routes.onboarding);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue