Skip to content

Commit

Permalink
fix(gebura): reduce render stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Feb 21, 2024
1 parent 61a0d29 commit 044f610
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 147 deletions.
28 changes: 16 additions & 12 deletions lib/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:local_hero/local_hero.dart';
import 'package:tuihub_protos/librarian/sephirah/v1/gebura.pb.dart';
import 'package:tuihub_protos/librarian/sephirah/v1/tiphereth.pb.dart';
import 'package:tuihub_protos/librarian/v1/common.pb.dart';
Expand Down Expand Up @@ -73,13 +74,13 @@ class AppRoutes {
}
}

void push(BuildContext context, {Object? extra}) {
unawaited(GoRouter.of(context).push(path, extra: extra));
if (isAction) {
OverlappingPanels.of(context)?.reveal(RevealSide.right);
FramePage.of(context)?.openDrawer();
}
}
// void push(BuildContext context, {Object? extra}) {
// unawaited(GoRouter.of(context).push(path, extra: extra));
// if (isAction) {
// OverlappingPanels.of(context)?.reveal(RevealSide.right);
// FramePage.of(context)?.openDrawer();
// }
// }

void pop(BuildContext context) {
if (isAction) {
Expand Down Expand Up @@ -438,12 +439,15 @@ GoRouter getRouter(MainBloc mainBloc, ApiHelper apiHelper) {
return CustomTransitionPage(
key: state.pageKey,
transitionsBuilder: (_, __, ___, child) => child,
child: FramePage(
selectedNav: ModuleName.gebura,
leftPart: GeburaNav(
function: function,
child: LocalHeroScope(
curve: Curves.easeInOut,
child: FramePage(
selectedNav: ModuleName.gebura,
leftPart: GeburaNav(
function: function,
),
middlePart: page,
),
middlePart: page,
),
);
},
Expand Down
3 changes: 2 additions & 1 deletion lib/view/pages/gebura/gebura_library_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:fixnum/fixnum.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:local_hero/local_hero.dart';
import 'package:tuihub_protos/librarian/sephirah/v1/gebura.pb.dart';
import 'package:tuihub_protos/librarian/v1/common.pb.dart';

Expand Down Expand Up @@ -117,7 +118,7 @@ class GeburaLibraryDetailPage extends StatelessWidget {
xxs: 3,
child: Padding(
padding: const EdgeInsets.all(8),
child: Hero(
child: LocalHero(
tag: item.id.id.toString(),
child: UrlHelper.isValidUrl(item.coverImageUrl)
? ExtendedImage.network(
Expand Down
6 changes: 3 additions & 3 deletions lib/view/pages/gebura/gebura_library_overview.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:local_hero/local_hero.dart';
import 'package:tuihub_protos/librarian/v1/common.pb.dart';

import '../../../bloc/gebura/gebura_bloc.dart';
Expand Down Expand Up @@ -115,8 +116,7 @@ class _GeburaLibraryOverviewItemState
context
.read<GeburaBloc>()
.add(GeburaSetSelectedLibraryItemEvent(widget.item.id));
AppRoutes.geburaLibraryDetail(widget.item.id.id.toInt())
.push(context);
AppRoutes.geburaLibraryDetail(widget.item.id.id.toInt()).go(context);
},
child: Stack(
children: [
Expand All @@ -130,7 +130,7 @@ class _GeburaLibraryOverviewItemState
child: Center(child: Text(noCoverImage ? name : '')),
),
Center(
child: Hero(
child: LocalHero(
tag: widget.item.id.id.toString(),
child: noCoverImage
? Container()
Expand Down
264 changes: 133 additions & 131 deletions lib/view/pages/gebura/gebura_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,147 +19,149 @@ class GeburaNav extends StatelessWidget {
Widget build(BuildContext context) {
var firstBuild = true;
final searchController = TextEditingController();
return BlocBuilder<GeburaBloc, GeburaState>(builder: (context, state) {
if (firstBuild) {
firstBuild = false;
if (state.libraryItems == null) {
context.read<GeburaBloc>().add(GeburaInitEvent());
return BlocBuilder<GeburaBloc, GeburaState>(
buildWhen: (previous, current) {
return previous.libraryItems != current.libraryItems ||
previous.selectedLibraryItem != current.selectedLibraryItem;
},
builder: (context, state) {
if (firstBuild) {
firstBuild = false;
if (state.libraryItems == null) {
context.read<GeburaBloc>().add(GeburaInitEvent());
}
}
}

return Column(
children: [
ListTile(
leading: const Icon(
Icons.shopping_cart,
),
onTap: () {
AppRoutes.geburaStore.go(context);
context
.read<GeburaBloc>()
.add(GeburaSetSelectedLibraryItemEvent(null));
OverlappingPanels.of(context)?.reveal(RevealSide.main);
},
title: Text(S.of(context).store),
selected: function == GeburaFunctions.store,
),
ListTile(
leading: const Icon(
Icons.apps,
return Column(
children: [
ListTile(
leading: const Icon(
Icons.shopping_cart,
),
onTap: () {
AppRoutes.geburaStore.go(context);
context
.read<GeburaBloc>()
.add(GeburaSetSelectedLibraryItemEvent(null));
OverlappingPanels.of(context)?.reveal(RevealSide.main);
},
title: Text(S.of(context).store),
selected: function == GeburaFunctions.store,
),
onTap: () {
context
.read<GeburaBloc>()
.add(GeburaSetSelectedLibraryItemEvent(null));
AppRoutes.geburaLibrary.push(context);
OverlappingPanels.of(context)?.reveal(RevealSide.main);
},
title: Text(S.of(context).library),
selected: function == GeburaFunctions.library &&
state.selectedLibraryItem == null,
),
SpacingHelper.defaultDivider,
Container(
padding: const EdgeInsets.only(bottom: 4),
child: TextField(
controller: searchController,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.filter_alt_outlined),
suffixIcon: state.librarySettings?.query?.isNotEmpty ?? false
? IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
context
.read<GeburaBloc>()
.add(GeburaApplyLibrarySettingsEvent(query: ''));
searchController.clear();
},
)
: null,
contentPadding: EdgeInsets.zero,
enabledBorder: OutlineInputBorder(
borderRadius: SpacingHelper.defaultBorderRadius,
borderSide: const BorderSide(
style: BorderStyle.none,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: SpacingHelper.defaultBorderRadius,
),
ListTile(
leading: const Icon(
Icons.apps,
),
onChanged: (query) {
onTap: () {
AppRoutes.geburaLibrary.go(context);
context
.read<GeburaBloc>()
.add(GeburaApplyLibrarySettingsEvent(query: query));
.add(GeburaSetSelectedLibraryItemEvent(null));
OverlappingPanels.of(context)?.reveal(RevealSide.main);
},
title: Text(S.of(context).library),
selected: function == GeburaFunctions.library &&
state.selectedLibraryItem == null,
),
SpacingHelper.defaultDivider,
Container(
padding: const EdgeInsets.only(bottom: 4),
child: TextField(
controller: searchController,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.filter_alt_outlined),
suffixIcon: state.librarySettings?.query?.isNotEmpty ?? false
? IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
context.read<GeburaBloc>().add(
GeburaApplyLibrarySettingsEvent(query: ''));
searchController.clear();
},
)
: null,
contentPadding: EdgeInsets.zero,
enabledBorder: OutlineInputBorder(
borderRadius: SpacingHelper.defaultBorderRadius,
borderSide: const BorderSide(
style: BorderStyle.none,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: SpacingHelper.defaultBorderRadius,
),
),
onChanged: (query) {
context
.read<GeburaBloc>()
.add(GeburaApplyLibrarySettingsEvent(query: query));
},
),
),
),
Expanded(
child: DynMouseScroll(
builder: (context, controller, physics) {
return SingleChildScrollView(
controller: controller,
physics: physics,
child: (state.libraryItems != null &&
state.libraryItems!.isNotEmpty)
? Column(
children: [
for (final AppInfoMixed app
in state.libraryItems ?? [])
ListTile(
selected: app.id.id.toInt() ==
state.selectedLibraryItem,
onTap: () {
context.read<GeburaBloc>().add(
GeburaSetSelectedLibraryItemEvent(
app.id));
AppRoutes.geburaLibraryDetail(
app.id.id.toInt())
.push(context);
OverlappingPanels.of(context)
?.reveal(RevealSide.main);
},
leading: Container(
decoration: app.iconImageUrl.isEmpty
? const BoxDecoration()
: BoxDecoration(
borderRadius:
BorderRadius.circular(4),
image: DecorationImage(
image: ExtendedNetworkImageProvider(
app.iconImageUrl,
),
fit: BoxFit.scaleDown,
Expanded(
child: DynMouseScroll(
builder: (context, controller, physics) {
return ListView(
controller: controller,
physics: physics,
children: [
if (state.libraryItems != null &&
state.libraryItems!.isNotEmpty)
for (final AppInfoMixed app
in state.libraryItems ?? [])
Material(
child: ListTile(
// https://github.com/flutter/flutter/issues/86584
selected: app.id.id.toInt() ==
state.selectedLibraryItem,
onTap: () {
AppRoutes.geburaLibraryDetail(app.id.id.toInt())
.go(context);
context.read<GeburaBloc>().add(
GeburaSetSelectedLibraryItemEvent(app.id));
OverlappingPanels.of(context)
?.reveal(RevealSide.main);
},
leading: Container(
decoration: app.iconImageUrl.isEmpty
? const BoxDecoration()
: BoxDecoration(
borderRadius: BorderRadius.circular(4),
image: DecorationImage(
image: ExtendedNetworkImageProvider(
app.iconImageUrl,
),
fit: BoxFit.scaleDown,
),
height: 24,
width: 24,
),
title: Text(app.name.isEmpty
? app.id.id.toHexString()
: app.name),
)
],
)
: (state is GeburaRefreshLibraryState)
? (state.processing)
? const Center(
child: CircularProgressIndicator(),
)
: (state.failed)
? Center(
child: Text(S
.of(context)
.loadFailed(state.msg ?? '')),
),
height: 24,
width: 24,
),
title: Text(app.name.isEmpty
? app.id.id.toHexString()
: app.name),
))
else
(state is GeburaRefreshLibraryState)
? (state.processing)
? const Center(
child: CircularProgressIndicator(),
)
: Container()
: Container(),
);
},
),
)
],
);
});
: (state.failed)
? Center(
child: Text(S
.of(context)
.loadFailed(state.msg ?? '')),
)
: Container()
: Container(),
]);
},
),
)
],
);
},
);
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies:
extended_image: ^8.2.0
font_awesome_flutter: ^10.7.0
buttons_tabbar: ^1.3.8
local_hero: ^0.3.0

# rust bridge
ffi: ^2.0.1
Expand Down

0 comments on commit 044f610

Please sign in to comment.