Skip to content

Commit

Permalink
remove some listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 29, 2024
1 parent 07807c9 commit 3f58af6
Showing 1 changed file with 61 additions and 73 deletions.
134 changes: 61 additions & 73 deletions lib/Frontend/pages/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:multi_listenable_builder/multi_listenable_builder.dart';
import 'package:multi_value_listenable_builder/multi_value_listenable_builder.dart';

import '../../Backend/Definitions/Action/base_action.dart';
import '../../Backend/Definitions/Device/device_definition.dart';
Expand Down Expand Up @@ -46,84 +44,74 @@ class _ActionPageBuilderState extends ConsumerState<ActionPageBuilder> {
Widget build(BuildContext context) {
bool largerCards = HiveProxy.getOrDefault(settings, largerActionCardSize, defaultValue: largerActionCardSizeDefault);
List<BaseStatefulDevice> knownDevicesFiltered = ref.watch(getAvailableGearProvider).toList();
return MultiValueListenableBuilder(
builder: (context, values, child) {
BuiltMap<ActionCategory, BuiltSet<BaseAction>> actionsCatMap = ref.watch(getAvailableActionsProvider);
List<ActionCategory> catList = actionsCatMap.keys.toList();
return AnimatedCrossFade(
firstChild: const Home(),
secondChild: MultiListenableBuilder(
builder: (BuildContext context, Widget? child) {
return ListView(
shrinkWrap: true,
children: [
AnimatedCrossFade(
firstChild: PageInfoCard(
text: actionsFavoriteTip(),
BuiltMap<ActionCategory, BuiltSet<BaseAction>> actionsCatMap = ref.watch(getAvailableActionsProvider);
List<ActionCategory> catList = actionsCatMap.keys.toList();
return AnimatedCrossFade(
firstChild: const Home(),
secondChild: ListView(
shrinkWrap: true,
children: [
AnimatedCrossFade(
firstChild: PageInfoCard(
text: actionsFavoriteTip(),
),
secondChild: GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(maxCrossAxisExtent: largerCards ? 250 : 125),
itemCount: actionsCatMap.values.flattened
.where(
(element) => ref.watch(favoriteActionsProvider).any((favorite) => favorite.actionUUID == element.uuid),
)
.length,
itemBuilder: (BuildContext context, int index) {
BaseAction baseAction = actionsCatMap.values.flattened
.where(
(element) => ref.watch(favoriteActionsProvider).any((favorite) => favorite.actionUUID == element.uuid),
)
.toList()[index];
return ActionCard(actionIndex: index, knownDevices: knownDevicesFiltered, action: baseAction, largerCards: largerCards);
},
),
crossFadeState: actionsCatMap.values.flattened.where((element) => ref.watch(favoriteActionsProvider.notifier).contains(element)).isEmpty ? CrossFadeState.showFirst : CrossFadeState.showSecond,
duration: animationTransitionDuration,
),
ListView.builder(
shrinkWrap: true,
itemCount: catList.length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int categoryIndex) {
List<BaseAction> actionsForCat = actionsCatMap.values.toList()[categoryIndex].toList();
return FadeIn(
delay: Duration(milliseconds: 100 * categoryIndex),
child: ListView(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: [
Center(
child: Text(
catList[categoryIndex].friendly,
style: Theme.of(context).textTheme.titleLarge,
),
),
secondChild: GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
GridView.builder(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(maxCrossAxisExtent: largerCards ? 250 : 125),
itemCount: actionsCatMap.values.flattened
.where(
(element) => ref.watch(favoriteActionsProvider).any((favorite) => favorite.actionUUID == element.uuid),
)
.length,
itemBuilder: (BuildContext context, int index) {
BaseAction baseAction = actionsCatMap.values.flattened
.where(
(element) => ref.watch(favoriteActionsProvider).any((favorite) => favorite.actionUUID == element.uuid),
)
.toList()[index];
return ActionCard(actionIndex: index, knownDevices: knownDevicesFiltered, action: baseAction, largerCards: largerCards);
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: actionsForCat.length,
itemBuilder: (BuildContext context, int actionIndex) {
return ActionCard(actionIndex: actionIndex, knownDevices: knownDevicesFiltered, action: actionsForCat[actionIndex], largerCards: largerCards);
},
),
crossFadeState: actionsCatMap.values.flattened.where((element) => ref.watch(favoriteActionsProvider.notifier).contains(element)).isEmpty ? CrossFadeState.showFirst : CrossFadeState.showSecond,
duration: animationTransitionDuration,
),
ListView.builder(
shrinkWrap: true,
itemCount: catList.length,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int categoryIndex) {
List<BaseAction> actionsForCat = actionsCatMap.values.toList()[categoryIndex].toList();
return FadeIn(
delay: Duration(milliseconds: 100 * categoryIndex),
child: ListView(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: [
Center(
child: Text(
catList[categoryIndex].friendly,
style: Theme.of(context).textTheme.titleLarge,
),
),
GridView.builder(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(maxCrossAxisExtent: largerCards ? 250 : 125),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: actionsForCat.length,
itemBuilder: (BuildContext context, int actionIndex) {
return ActionCard(actionIndex: actionIndex, knownDevices: knownDevicesFiltered, action: actionsForCat[actionIndex], largerCards: largerCards);
},
),
],
),
);
},
),
],
],
),
);
},
notifiers: knownDevicesFiltered.isNotEmpty ? knownDevicesFiltered.map((e) => e.baseStoredDevice).toList() : [ChangeNotifier()],
),
crossFadeState: actionsCatMap.isNotEmpty ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: animationTransitionDuration,
);
},
valueListenables: knownDevicesFiltered.isEmpty ? [ValueNotifier(false)] : knownDevicesFiltered.map((e) => e.hasGlowtip).toList(),
],
),
crossFadeState: actionsCatMap.isNotEmpty ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: animationTransitionDuration,
);
}
}
Expand Down

0 comments on commit 3f58af6

Please sign in to comment.