fixed filter chip hero to filter bar
This commit is contained in:
parent
cb21761a47
commit
209bb70f03
2 changed files with 23 additions and 11 deletions
|
@ -33,8 +33,10 @@ class FilterBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
final filter = filters[index];
|
final filter = filters[index];
|
||||||
return Center(
|
return Center(
|
||||||
child: AvesFilterChip(
|
child: AvesFilterChip(
|
||||||
|
key: ValueKey(filter),
|
||||||
filter: filter,
|
filter: filter,
|
||||||
removable: true,
|
removable: true,
|
||||||
|
heroType: HeroType.always,
|
||||||
onPressed: collection.removeFilter,
|
onPressed: collection.removeFilter,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,12 +4,15 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
typedef FilterCallback = void Function(CollectionFilter filter);
|
typedef FilterCallback = void Function(CollectionFilter filter);
|
||||||
|
|
||||||
|
enum HeroType { always, onTap, never }
|
||||||
|
|
||||||
class AvesFilterChip extends StatefulWidget {
|
class AvesFilterChip extends StatefulWidget {
|
||||||
final CollectionFilter filter;
|
final CollectionFilter filter;
|
||||||
final bool removable;
|
final bool removable;
|
||||||
final bool showGenericIcon;
|
final bool showGenericIcon;
|
||||||
final Decoration decoration;
|
final Decoration decoration;
|
||||||
final Widget details;
|
final Widget details;
|
||||||
|
final HeroType heroType;
|
||||||
final FilterCallback onPressed;
|
final FilterCallback onPressed;
|
||||||
|
|
||||||
static final BorderRadius borderRadius = BorderRadius.circular(32);
|
static final BorderRadius borderRadius = BorderRadius.circular(32);
|
||||||
|
@ -27,6 +30,7 @@ class AvesFilterChip extends StatefulWidget {
|
||||||
this.showGenericIcon = true,
|
this.showGenericIcon = true,
|
||||||
this.decoration,
|
this.decoration,
|
||||||
this.details,
|
this.details,
|
||||||
|
this.heroType = HeroType.onTap,
|
||||||
@required this.onPressed,
|
@required this.onPressed,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@ -36,6 +40,7 @@ class AvesFilterChip extends StatefulWidget {
|
||||||
|
|
||||||
class _AvesFilterChipState extends State<AvesFilterChip> {
|
class _AvesFilterChipState extends State<AvesFilterChip> {
|
||||||
Future<Color> _colorFuture;
|
Future<Color> _colorFuture;
|
||||||
|
bool _tapped;
|
||||||
|
|
||||||
CollectionFilter get filter => widget.filter;
|
CollectionFilter get filter => widget.filter;
|
||||||
|
|
||||||
|
@ -43,6 +48,7 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_initColorLoader();
|
_initColorLoader();
|
||||||
|
_tapped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -50,6 +56,7 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
if (oldWidget.filter != filter) {
|
if (oldWidget.filter != filter) {
|
||||||
_initColorLoader();
|
_initColorLoader();
|
||||||
|
_tapped = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +126,7 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
||||||
|
|
||||||
final borderRadius = AvesFilterChip.borderRadius;
|
final borderRadius = AvesFilterChip.borderRadius;
|
||||||
|
|
||||||
final chip = Container(
|
Widget chip = Container(
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
minWidth: AvesFilterChip.minChipWidth,
|
minWidth: AvesFilterChip.minChipWidth,
|
||||||
maxWidth: AvesFilterChip.maxChipWidth,
|
maxWidth: AvesFilterChip.maxChipWidth,
|
||||||
|
@ -135,7 +142,12 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
),
|
),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: widget.onPressed != null ? () => widget.onPressed(filter) : null,
|
onTap: widget.onPressed != null
|
||||||
|
? () {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => widget.onPressed(filter));
|
||||||
|
setState(() => _tapped = true);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: _colorFuture,
|
future: _colorFuture,
|
||||||
|
@ -162,14 +174,12 @@ class _AvesFilterChipState extends State<AvesFilterChip> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO TLAD only hero between `FilterBar` and chips that are tapped
|
if (widget.heroType == HeroType.always || widget.heroType == HeroType.onTap && _tapped) {
|
||||||
return Hero(
|
chip = Hero(
|
||||||
tag: filter,
|
tag: filter,
|
||||||
flightShuttleBuilder: (flight, animation, direction, fromHeroContext, toHeroContext) {
|
|
||||||
final toHero = toHeroContext.widget as Hero;
|
|
||||||
return Center(child: toHero.child);
|
|
||||||
},
|
|
||||||
child: chip,
|
child: chip,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return chip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue