Skip to content

Instantly share code, notes, and snippets.

@samuelchanx
Created December 19, 2022 11:00
Show Gist options
  • Select an option

  • Save samuelchanx/0071e388e63d6381024842cd4baf1bf3 to your computer and use it in GitHub Desktop.

Select an option

Save samuelchanx/0071e388e63d6381024842cd4baf1bf3 to your computer and use it in GitHub Desktop.
Flutter hooks #dart #flutter
class ShopCouponList extends HookConsumerWidget {
final ShopCouponType type;
const ShopCouponList({
super.key,
required this.type,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
const loadingWidget = Padding(
padding: EdgeInsets.symmetric(vertical: 32.0),
child: CircularProgressIndicator(),
);
final notifier = useValueNotifier<bool>(true);
return ref.watch(shopCouponListProvider(type)).when(
data: (data) => ListView.builder(
// physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
primary: false,
itemCount: data.length,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
itemBuilder: (BuildContext context, int index) {
return HookBuilder(
builder: (context) {
final value = useValueListenable(notifier);
return InkWell(
onTap: () {
notifier.value = !notifier.value;
},
child: ShopCouponListItem(
coupon: data[index],
),
);
}
);
},
),
error: (error, stack) => loadingWidget,
loading: () => loadingWidget,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment