Created
December 19, 2022 11:00
-
-
Save samuelchanx/0071e388e63d6381024842cd4baf1bf3 to your computer and use it in GitHub Desktop.
Flutter hooks #dart #flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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