♻️ 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,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 {