♻️ Refactor router, moved from auto_router to go_router

This commit is contained in:
2025-06-26 14:13:44 +08:00
parent 825e6b5b6d
commit f2829b2012
67 changed files with 587 additions and 2876 deletions

View File

@ -1,13 +1,12 @@
import 'package:auto_route/auto_route.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:gap/gap.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/post.dart';
import 'package:island/pods/network.dart';
import 'package:island/route.gr.dart';
import 'package:island/screens/creators/publishers.dart';
import 'package:island/services/responsive.dart';
import 'package:island/widgets/alert.dart';
@ -27,9 +26,9 @@ Future<SnPublisherStats?> publisherStats(Ref ref, String? uname) async {
return SnPublisherStats.fromJson(resp.data);
}
@RoutePage()
class CreatorHubShellScreen extends StatelessWidget {
const CreatorHubShellScreen({super.key});
final Widget child;
const CreatorHubShellScreen({super.key, required this.child});
@override
Widget build(BuildContext context) {
@ -39,15 +38,14 @@ class CreatorHubShellScreen extends StatelessWidget {
children: [
SizedBox(width: 360, child: const CreatorHubScreen(isAside: true)),
const VerticalDivider(width: 1),
Expanded(child: AutoRouter()),
Expanded(child: child),
],
);
}
return AutoRouter();
return child;
}
}
@RoutePage()
class CreatorHubScreen extends HookConsumerWidget {
final bool isAside;
const CreatorHubScreen({super.key, this.isAside = false});
@ -65,8 +63,8 @@ class CreatorHubScreen extends HookConsumerWidget {
);
void updatePublisher() {
context.router
.push(EditPublisherRoute(name: currentPublisher.value!.name))
context
.push('/creators/${currentPublisher.value!.name}/edit')
.then((value) async {
if (value == null) return;
final data = await ref.refresh(publishersManagedProvider.future);
@ -223,7 +221,7 @@ class CreatorHubScreen extends HookConsumerWidget {
subtitle: Text('createPublisherHint').tr(),
trailing: const Icon(Symbols.chevron_right),
onTap: () {
context.router.push(NewPublisherRoute()).then((
context.push('/creators/publishers/new').then((
value,
) {
if (value != null) {
@ -249,10 +247,8 @@ class CreatorHubScreen extends HookConsumerWidget {
horizontal: 24,
),
onTap: () {
context.router.push(
StickersRoute(
pubName: currentPublisher.value!.name,
),
context.push(
'/creators/${currentPublisher.value!.name}/stickers',
);
},
),
@ -265,10 +261,8 @@ class CreatorHubScreen extends HookConsumerWidget {
horizontal: 24,
),
onTap: () {
context.router.push(
CreatorPostListRoute(
pubName: currentPublisher.value!.name,
),
context.push(
'/creators/${currentPublisher.value!.name}/posts',
);
},
),

View File

@ -1,6 +1,6 @@
import 'package:auto_route/auto_route.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/widgets/app_scaffold.dart';
@ -8,13 +8,9 @@ import 'package:island/widgets/content/sheet.dart';
import 'package:island/widgets/post/post_list.dart';
import 'package:material_symbols_icons/symbols.dart';
@RoutePage()
class CreatorPostListScreen extends HookConsumerWidget {
final String pubName;
const CreatorPostListScreen({
super.key,
@PathParam('name') required this.pubName,
});
const CreatorPostListScreen({super.key, required this.pubName});
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -34,7 +30,7 @@ class CreatorPostListScreen extends HookConsumerWidget {
subtitle: Text('Create a regular post'),
onTap: () async {
Navigator.pop(context);
final result = await context.router.pushPath(
final result = await context.push(
'/posts/compose?type=0',
);
if (result == true) {
@ -48,7 +44,7 @@ class CreatorPostListScreen extends HookConsumerWidget {
subtitle: Text('Create a detailed article'),
onTap: () async {
Navigator.pop(context);
final result = await context.router.pushPath(
final result = await context.push(
'/posts/compose?type=1',
);
if (result == true) {

View File

@ -1,10 +1,10 @@
import 'package:auto_route/auto_route.dart';
import 'package:collection/collection.dart';
import 'package:croppy/croppy.dart' hide cropImage;
import 'package:dio/dio.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:image_picker/image_picker.dart';
import 'package:island/models/file.dart';
@ -44,7 +44,6 @@ Future<SnPublisher?> publisher(Ref ref, String? identifier) async {
return SnPublisher.fromJson(resp.data);
}
@RoutePage()
class NewPublisherScreen extends StatelessWidget {
const NewPublisherScreen({super.key});
@ -54,10 +53,9 @@ class NewPublisherScreen extends StatelessWidget {
}
}
@RoutePage()
class EditPublisherScreen extends HookConsumerWidget {
final String? name;
const EditPublisherScreen({super.key, @PathParam('id') this.name});
const EditPublisherScreen({super.key, this.name});
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -177,7 +175,7 @@ class EditPublisherScreen extends HookConsumerWidget {
options: Options(method: name == null ? 'POST' : 'PATCH'),
);
if (context.mounted) {
context.maybePop(SnPublisher.fromJson(resp.data));
context.pop(SnPublisher.fromJson(resp.data));
}
} catch (err) {
showErrorAlert(err);

View File

@ -1,7 +1,7 @@
import 'package:auto_route/auto_route.dart';
import 'package:dio/dio.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@ -10,7 +10,6 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/sticker.dart';
import 'package:island/pods/network.dart';
import 'package:island/route.gr.dart';
import 'package:island/screens/creators/stickers/stickers.dart';
import 'package:island/widgets/alert.dart';
import 'package:island/widgets/app_scaffold.dart';
@ -34,14 +33,13 @@ Future<List<SnSticker>> stickerPackContent(Ref ref, String packId) async {
.toList();
}
@RoutePage()
class StickerPackDetailScreen extends HookConsumerWidget {
final String id;
final String pubName;
const StickerPackDetailScreen({
super.key,
@PathParam('name') required this.pubName,
@PathParam('packId') required this.id,
required this.pubName,
required this.id,
});
@override
@ -76,7 +74,7 @@ class StickerPackDetailScreen extends HookConsumerWidget {
IconButton(
icon: const Icon(Symbols.add_circle),
onPressed: () {
AutoRouter.of(context).push(NewStickersRoute(packId: id)).then((
context.push('/creators/stickers/$id/new').then((
value,
) {
if (value != null) {
@ -175,12 +173,9 @@ class StickerPackDetailScreen extends HookConsumerWidget {
title: 'edit'.tr(),
image: MenuImage.icon(Symbols.edit),
callback: () {
context.router
context
.push(
EditStickersRoute(
packId: id,
id: sticker.id,
),
'/creators/stickers/$id/edit/${sticker.id}',
)
.then((value) {
if (value != null) {
@ -264,8 +259,8 @@ class _StickerPackActionMenu extends HookConsumerWidget {
(context) => [
PopupMenuItem(
onTap: () {
context.router.push(
EditStickerPacksRoute(pubName: pubName, packId: packId),
context.push(
'/creators/$pubName/stickers/$packId/edit',
);
},
child: Row(
@ -299,7 +294,7 @@ class _StickerPackActionMenu extends HookConsumerWidget {
final client = ref.watch(apiClientProvider);
client.delete('/stickers/$packId');
ref.invalidate(stickerPacksNotifierProvider);
if (context.mounted) context.router.maybePop(true);
if (context.mounted) context.pop(true);
}
});
},
@ -331,13 +326,9 @@ Future<SnSticker?> stickerPackSticker(
return SnSticker.fromJson(resp.data);
}
@RoutePage()
class NewStickersScreen extends StatelessWidget {
final String packId;
const NewStickersScreen({
super.key,
@PathParam('packId') required this.packId,
});
const NewStickersScreen({super.key, required this.packId});
@override
Widget build(BuildContext context) {
@ -345,15 +336,10 @@ class NewStickersScreen extends StatelessWidget {
}
}
@RoutePage()
class EditStickersScreen extends HookConsumerWidget {
final String packId;
final String? id;
const EditStickersScreen({
super.key,
@PathParam("packId") required this.packId,
@PathParam("id") required this.id,
});
const EditStickersScreen({super.key, required this.packId, required this.id});
@override
Widget build(BuildContext context, WidgetRef ref) {

View File

@ -22,14 +22,11 @@ mixin _$StickerWithPackQuery {
@pragma('vm:prefer-inline')
$StickerWithPackQueryCopyWith<StickerWithPackQuery> get copyWith => _$StickerWithPackQueryCopyWithImpl<StickerWithPackQuery>(this as StickerWithPackQuery, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is StickerWithPackQuery&&(identical(other.packId, packId) || other.packId == packId)&&(identical(other.id, id) || other.id == id));
}
@override
int get hashCode => Object.hash(runtimeType,packId,id);
@ -38,7 +35,6 @@ String toString() {
return 'StickerWithPackQuery(packId: $packId, id: $id)';
}
}
/// @nodoc
@ -49,9 +45,6 @@ $Res call({
String packId, String id
});
}
/// @nodoc
class _$StickerWithPackQueryCopyWithImpl<$Res>
@ -73,10 +66,8 @@ as String,
}
/// @nodoc
class _StickerWithPackQuery implements StickerWithPackQuery {
const _StickerWithPackQuery({required this.packId, required this.id});
@ -90,14 +81,11 @@ class _StickerWithPackQuery implements StickerWithPackQuery {
@pragma('vm:prefer-inline')
_$StickerWithPackQueryCopyWith<_StickerWithPackQuery> get copyWith => __$StickerWithPackQueryCopyWithImpl<_StickerWithPackQuery>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _StickerWithPackQuery&&(identical(other.packId, packId) || other.packId == packId)&&(identical(other.id, id) || other.id == id));
}
@override
int get hashCode => Object.hash(runtimeType,packId,id);
@ -106,7 +94,6 @@ String toString() {
return 'StickerWithPackQuery(packId: $packId, id: $id)';
}
}
/// @nodoc
@ -117,9 +104,6 @@ $Res call({
String packId, String id
});
}
/// @nodoc
class __$StickerWithPackQueryCopyWithImpl<$Res>
@ -139,7 +123,6 @@ as String,
));
}
}
// dart format on

View File

@ -1,13 +1,12 @@
import 'package:auto_route/auto_route.dart';
import 'package:dio/dio.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:gap/gap.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/models/sticker.dart';
import 'package:island/pods/network.dart';
import 'package:island/route.gr.dart';
import 'package:island/widgets/alert.dart';
import 'package:island/widgets/app_scaffold.dart';
import 'package:material_symbols_icons/symbols.dart';
@ -17,10 +16,9 @@ import 'package:riverpod_paging_utils/riverpod_paging_utils.dart';
part 'stickers.g.dart';
@RoutePage()
class StickersScreen extends HookConsumerWidget {
final String pubName;
const StickersScreen({super.key, @PathParam("name") required this.pubName});
const StickersScreen({super.key, required this.pubName});
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -30,7 +28,7 @@ class StickersScreen extends HookConsumerWidget {
actions: [
IconButton(
onPressed: () {
context.router.push(NewStickerPacksRoute(pubName: pubName)).then((
context.push('/creators/stickers/new?pubName=pubName').then((
value,
) {
if (value != null) {
@ -73,8 +71,8 @@ class SliverStickerPacksList extends HookConsumerWidget {
subtitle: Text(sticker.description),
trailing: const Icon(Symbols.chevron_right),
onTap: () {
context.router.push(
StickerPackDetailRoute(pubName: pubName, id: sticker.id),
context.push(
'/creators/$pubName/stickers/${sticker.id}',
);
},
);
@ -137,13 +135,9 @@ Future<SnStickerPack?> stickerPack(Ref ref, String? packId) async {
return SnStickerPack.fromJson(resp.data);
}
@RoutePage()
class NewStickerPacksScreen extends HookConsumerWidget {
final String pubName;
const NewStickerPacksScreen({
super.key,
@PathParam("name") required this.pubName,
});
const NewStickerPacksScreen({super.key, required this.pubName});
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -151,15 +145,10 @@ class NewStickerPacksScreen extends HookConsumerWidget {
}
}
@RoutePage()
class EditStickerPacksScreen extends HookConsumerWidget {
final String pubName;
final String? packId;
const EditStickerPacksScreen({
super.key,
@PathParam("name") required this.pubName,
@PathParam("packId") this.packId,
});
const EditStickerPacksScreen({super.key, required this.pubName, this.packId});
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -200,7 +189,7 @@ class EditStickerPacksScreen extends HookConsumerWidget {
),
);
if (!context.mounted) return;
context.router.maybePop(SnStickerPack.fromJson(resp.data));
context.pop(SnStickerPack.fromJson(resp.data));
} catch (err) {
showErrorAlert(err);
} finally {