Skip to content

Commit

Permalink
change: 添加页面转跳动画 (#172)
Browse files Browse the repository at this point in the history
* 各种主页使用 FadeTransition

* 不再通过物品或位置名称转跳到对应页面

* 调整评论排序的图标
  • Loading branch information
he0119 authored Nov 7, 2021
1 parent 32a6c9a commit 2e5932b
Show file tree
Hide file tree
Showing 21 changed files with 381 additions and 497 deletions.
9 changes: 7 additions & 2 deletions lib/blog/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ class BlogHomePage extends Page {

@override
Route createRoute(BuildContext context) {
return MaterialPageRoute(
return PageRouteBuilder(
settings: this,
builder: (context) => const BlogHomeScreen(),
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) =>
FadeTransition(
opacity: animation,
child: BlogHomeScreen(),
),
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/board/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ class BoardHomePage extends Page {
@override
Route createRoute(BuildContext context) {
BlocProvider.of<BoardHomeBloc>(context).add(const BoardHomeFetched());
return MaterialPageRoute(
return PageRouteBuilder(
settings: this,
builder: (context) => const BoardHomeScreen(),
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) =>
FadeTransition(
opacity: animation,
child: BoardHomeScreen(),
),
);
}
}
Expand Down
90 changes: 53 additions & 37 deletions lib/board/view/topic_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ class TopicDetailPage extends Page {

@override
Route createRoute(BuildContext context) {
return MaterialPageRoute(
return PageRouteBuilder(
settings: this,
builder: (context) => TopicDetailScreen(
topicId: topicId,
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) =>
FadeTransition(
opacity: animation,
child: TopicDetailScreen(
topicId: topicId,
),
),
);
}
Expand All @@ -50,12 +55,12 @@ class TopicDetailScreen extends StatelessWidget {
providers: [
BlocProvider<TopicDetailBloc>(
create: (context) => TopicDetailBloc(
boardRepository: RepositoryProvider.of<BoardRepository>(context),
boardRepository: context.read<BoardRepository>(),
)..add(TopicDetailFetched(topicId: topicId, descending: descending)),
),
BlocProvider<TopicEditBloc>(
create: (context) => TopicEditBloc(
boardRepository: RepositoryProvider.of<BoardRepository>(context),
boardRepository: context.read<BoardRepository>(),
),
)
],
Expand All @@ -82,10 +87,10 @@ class _DetailScreen extends StatelessWidget {
appBar: AppBar(),
body: ErrorMessageButton(
onPressed: () {
BlocProvider.of<TopicDetailBloc>(context).add(
TopicDetailFetched(
topicId: state.topicId, descending: descending),
);
context.read<TopicDetailBloc>().add(
TopicDetailFetched(
topicId: state.topicId, descending: descending),
);
},
message: state.message,
),
Expand All @@ -94,7 +99,7 @@ class _DetailScreen extends StatelessWidget {
if (state is TopicDetailSuccess) {
return BlocProvider(
create: (context) => CommentEditBloc(
boardRepository: RepositoryProvider.of<BoardRepository>(context),
boardRepository: context.read<BoardRepository>(),
),
child: MultiBlocListener(
listeners: [
Expand Down Expand Up @@ -124,11 +129,10 @@ class _DetailScreen extends StatelessWidget {
BlocListener<CommentEditBloc, CommentEditState>(
listener: (context, state) {
if (state is CommentDeleteSuccess) {
BlocProvider.of<TopicDetailBloc>(context)
.add(TopicDetailFetched(
descending: descending,
cache: false,
));
context.read<TopicDetailBloc>().add(TopicDetailFetched(
descending: descending,
cache: false,
));
showInfoSnackBar('评论删除成功');
}
if (state is CommentFailure) {
Expand All @@ -142,11 +146,10 @@ class _DetailScreen extends StatelessWidget {
appBar: _buildAppBar(context, state, descending, loginUser),
body: RefreshIndicator(
onRefresh: () async {
BlocProvider.of<TopicDetailBloc>(context)
.add(TopicDetailFetched(
descending: descending,
cache: false,
));
context.read<TopicDetailBloc>().add(TopicDetailFetched(
descending: descending,
cache: false,
));
},
child: InfiniteList<Comment>(
items: state.comments,
Expand Down Expand Up @@ -218,19 +221,18 @@ class _DetailScreen extends StatelessWidget {
MaterialPageRoute(
builder: (_) => BlocProvider(
create: (context) => TopicEditBloc(
boardRepository:
RepositoryProvider.of<BoardRepository>(context)),
boardRepository: context.read<BoardRepository>()),
child: TopicEditPage(
isEditing: true,
topic: state.topic,
),
),
),
);
BlocProvider.of<TopicDetailBloc>(context).add(TopicDetailFetched(
descending: descending,
cache: false,
));
context.read<TopicDetailBloc>().add(TopicDetailFetched(
descending: descending,
cache: false,
));
}
if (value == TopicDetailMenu.delete) {
await showDialog(
Expand All @@ -248,7 +250,8 @@ class _DetailScreen extends StatelessWidget {
TextButton(
onPressed: () {
showInfoSnackBar('正在删除...', duration: 1);
BlocProvider.of<TopicEditBloc>(context)
context
.read<TopicEditBloc>()
.add(TopicDeleted(topic: state.topic));
Navigator.pop(context);
},
Expand All @@ -274,7 +277,8 @@ class _DetailScreen extends StatelessWidget {
TextButton(
onPressed: () {
showInfoSnackBar('正在置顶...', duration: 1);
BlocProvider.of<TopicEditBloc>(context)
context
.read<TopicEditBloc>()
.add(TopicPinned(topic: state.topic));
Navigator.pop(context);
},
Expand All @@ -300,7 +304,8 @@ class _DetailScreen extends StatelessWidget {
TextButton(
onPressed: () {
showInfoSnackBar('正在取消...', duration: 1);
BlocProvider.of<TopicEditBloc>(context)
context
.read<TopicEditBloc>()
.add(TopicUnpinned(topic: state.topic));
Navigator.pop(context);
},
Expand All @@ -326,7 +331,8 @@ class _DetailScreen extends StatelessWidget {
TextButton(
onPressed: () {
showInfoSnackBar('正在关闭...', duration: 1);
BlocProvider.of<TopicEditBloc>(context)
context
.read<TopicEditBloc>()
.add(TopicClosed(topic: state.topic));
Navigator.pop(context);
},
Expand All @@ -352,7 +358,8 @@ class _DetailScreen extends StatelessWidget {
TextButton(
onPressed: () {
showInfoSnackBar('正在开启...', duration: 1);
BlocProvider.of<TopicEditBloc>(context)
context
.read<TopicEditBloc>()
.add(TopicReopened(topic: state.topic));
Navigator.pop(context);
},
Expand Down Expand Up @@ -424,14 +431,23 @@ class CommentOrder extends StatelessWidget {
const Spacer(),
PopupMenuButton(
tooltip: '评论排序',
icon: Icon(
descending ? Icons.arrow_downward : Icons.arrow_upward,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Icon(Icons.sort),
SizedBox(width: 4),
Text(descending ? '倒序' : '正序'),
],
),
),
onSelected: (dynamic value) {
BlocProvider.of<AppPreferencesBloc>(context)
.add(CommentDescendingChanged(descending: value));
BlocProvider.of<TopicDetailBloc>(context)
.add(TopicDetailFetched(topicId: topicId, descending: value));
context.read<AppPreferencesBloc>().add(
CommentDescendingChanged(descending: value),
);
context.read<TopicDetailBloc>().add(
TopicDetailFetched(topicId: topicId, descending: value),
);
},
itemBuilder: (context) => <PopupMenuItem<bool>>[
const PopupMenuItem(
Expand Down
6 changes: 2 additions & 4 deletions lib/core/view/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class SplashScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
return Scaffold(
body: Container(),
);
}
}
9 changes: 7 additions & 2 deletions lib/iot/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ class IotHomePage extends Page {

@override
Route createRoute(BuildContext context) {
return MaterialPageRoute(
return PageRouteBuilder(
settings: this,
builder: (context) => const IotHomeScreen(),
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) =>
FadeTransition(
opacity: animation,
child: IotHomeScreen(),
),
);
}
}
Expand Down
61 changes: 30 additions & 31 deletions lib/routers/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:smarthome/core/core.dart';
import 'package:smarthome/iot/iot.dart';
import 'package:smarthome/routers/information_parser.dart';
import 'package:smarthome/routers/route_path.dart';
import 'package:smarthome/routers/transition_delegate.dart';
import 'package:smarthome/storage/storage.dart';
import 'package:smarthome/utils/launch_url.dart';

Expand Down Expand Up @@ -84,11 +83,12 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
/// 添加一组位置
void addStorageGroup({Storage? storage}) {
storageGroup += 1;
_pages.add(StorageDetailPage(
storageName: storage?.name ?? '',
storageId: storage?.id,
group: storageGroup,
));
_pages.add(
StorageDetailPage(
storageId: storage?.id ?? '',
group: storageGroup,
),
);
notifyListeners();
}

Expand All @@ -102,22 +102,24 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
_pages.removeLast();
}
// 再重新添加
_pages.add(StorageDetailPage(storageName: '', group: storageGroup));
_pages.add(StorageDetailPage(storageId: '', group: storageGroup));
if (storage != null) {
if (storage.ancestors != null) {
for (var storage in storage.ancestors!) {
_pages.add(StorageDetailPage(
storageName: storage.name,
storageId: storage.id,
group: storageGroup,
));
_pages.add(
StorageDetailPage(
storageId: storage.id,
group: storageGroup,
),
);
}
}
_pages.add(StorageDetailPage(
storageName: storage.name,
storageId: storage.id,
group: storageGroup,
));
_pages.add(
StorageDetailPage(
storageId: storage.id,
group: storageGroup,
),
);
}
notifyListeners();
}
Expand All @@ -127,11 +129,12 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
/// 添加一个物品详情页面
void addItemPage({required Item item}) {
itemCount += 1;
_pages.add(ItemDetailPage(
itemName: item.name,
itemId: item.id,
group: itemCount,
));
_pages.add(
ItemDetailPage(
itemId: item.id,
group: itemCount,
),
);
notifyListeners();
}

Expand Down Expand Up @@ -176,9 +179,9 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
appTab: EnumToString.fromString(AppTab.values, uri.pathSegments[0]),
);
} else if (pages.last is StorageDetailPage) {
return StorageRoutePath(storageName: uri.pathSegments[2]);
return StorageRoutePath(storageId: uri.pathSegments[2]);
} else if (pages.last is ItemDetailPage) {
return ItemRoutePath(itemName: uri.pathSegments[1]);
return ItemRoutePath(itemId: uri.pathSegments[1]);
} else if (pages.last is TopicDetailPage) {
return TopicRoutePath(topicId: uri.pathSegments[1]);
} else if (pages.last is LoginPage) {
Expand Down Expand Up @@ -219,7 +222,6 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
_pages = [
const StorageHomePage(),
ItemDetailPage(
itemName: configuration.itemName,
itemId: configuration.itemId,
group: 1,
),
Expand All @@ -230,7 +232,6 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
_pages = [
const StorageHomePage(),
StorageDetailPage(
storageName: configuration.storageName,
storageId: configuration.storageId,
group: 1,
),
Expand Down Expand Up @@ -282,13 +283,11 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
}
}

TransitionDelegate transitionDelegate = MyTransitionDelegate();
// TransitionDelegate transitionDelegate = MyTransitionDelegate();

@override
Widget build(BuildContext context) {
_log
..fine('Router rebuilded')
..fine('pages $pages');
_log..fine('Router rebuilded')..fine('pages $pages');
final graphQLApiClient = RepositoryProvider.of<GraphQLApiClient>(context);
final config = AppConfig.of(context);
return MultiBlocListener(
Expand Down Expand Up @@ -418,7 +417,7 @@ class MyRouterDelegate extends RouterDelegate<RoutePath>
key: navigatorKey,
pages: pages,
onPopPage: _handlePopPage,
transitionDelegate: transitionDelegate,
// transitionDelegate: transitionDelegate,
),
);
}
Expand Down
Loading

0 comments on commit 2e5932b

Please sign in to comment.