From a14891c77a5f4a591fec45bc4dcc90919233db89 Mon Sep 17 00:00:00 2001 From: hawkbee1 Date: Thu, 10 Oct 2024 15:48:31 +0000 Subject: [PATCH] add card_swiper and basic configuration --- .../list/widgets/credential_list_widget.dart | 106 ++++++++++++++++++ .../home_credential_category_item.dart | 28 +---- pubspec.lock | 8 ++ pubspec.yaml | 1 + 4 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 lib/dashboard/home/tab_bar/credentials/list/widgets/credential_list_widget.dart diff --git a/lib/dashboard/home/tab_bar/credentials/list/widgets/credential_list_widget.dart b/lib/dashboard/home/tab_bar/credentials/list/widgets/credential_list_widget.dart new file mode 100644 index 000000000..778d93950 --- /dev/null +++ b/lib/dashboard/home/tab_bar/credentials/list/widgets/credential_list_widget.dart @@ -0,0 +1,106 @@ +import 'package:altme/app/shared/constants/sizes.dart'; +import 'package:altme/app/shared/enum/credential_category.dart'; +import 'package:altme/dashboard/home/tab_bar/credentials/list/widgets/home_credential_item.dart'; +import 'package:altme/dashboard/home/tab_bar/credentials/models/credential_model/credential_model.dart'; +import 'package:altme/dashboard/home/tab_bar/credentials/widgets/credential_widget/add_credential_button.dart'; +import 'package:card_swiper/card_swiper.dart'; +import 'package:flutter/material.dart'; + +class CredentialListWidget extends StatelessWidget { + const CredentialListWidget({ + super.key, + required this.sortedCredentials, + required this.credentialCategory, + }); + + final List sortedCredentials; + final CredentialCategory credentialCategory; + + @override + Widget build(BuildContext context) { + return CredentialListStack( + sortedCredentials: sortedCredentials, + credentialCategory: credentialCategory, + ); + } +} + +class CredentialListGrid extends StatelessWidget { + const CredentialListGrid({ + super.key, + required this.sortedCredentials, + required this.credentialCategory, + }); + + final List sortedCredentials; + final CredentialCategory credentialCategory; + + @override + Widget build(BuildContext context) { + return GridView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + crossAxisSpacing: 14, + mainAxisSpacing: 14, + childAspectRatio: Sizes.credentialAspectRatio, + ), + itemCount: sortedCredentials.length + 1, + itemBuilder: (_, index) { + if (index == sortedCredentials.length) { + if (credentialCategory == CredentialCategory.pendingCards) { + return Container(); + } + return AddCredentialButton( + credentialCategory: credentialCategory, + ); + } else { + return HomeCredentialItem( + credentialModel: sortedCredentials[index], + ); + } + }, + ); + } +} + +class CredentialListStack extends StatelessWidget { + const CredentialListStack({ + super.key, + required this.sortedCredentials, + required this.credentialCategory, + }); + + final List sortedCredentials; + final CredentialCategory credentialCategory; + + @override + Widget build(BuildContext context) { + const double cardHeight = 150; + return SizedBox( + height: 200, + child: Swiper( + scrollDirection: Axis.horizontal, + loop: false, + containerHeight: 200, + containerWidth: 150, + itemHeight: cardHeight, + itemWidth: cardHeight * 1.586, + layout: SwiperLayout.CUSTOM, + customLayoutOption: CustomLayoutOption(startIndex: -1, stateCount: 3) + ..addRotate([-60.0 / 180, 0.0, 60.0 / 180]) + ..addTranslate( + [Offset(-210.0, -20.0), Offset(0.0, 0.0), Offset(210.0, -20.0)]), + itemBuilder: (BuildContext context, int index) { + return HomeCredentialItem( + credentialModel: sortedCredentials[index], + ); + }, + itemCount: sortedCredentials.length, + pagination: SwiperPagination(), + control: SwiperControl(), + ), + ); + } +} diff --git a/lib/dashboard/home/tab_bar/credentials/list/widgets/home_credential_category_item.dart b/lib/dashboard/home/tab_bar/credentials/list/widgets/home_credential_category_item.dart index 2875d8f0b..50a9e57f4 100644 --- a/lib/dashboard/home/tab_bar/credentials/list/widgets/home_credential_category_item.dart +++ b/lib/dashboard/home/tab_bar/credentials/list/widgets/home_credential_category_item.dart @@ -1,5 +1,6 @@ import 'package:altme/app/app.dart'; import 'package:altme/dashboard/dashboard.dart'; +import 'package:altme/dashboard/home/tab_bar/credentials/list/widgets/credential_list_widget.dart'; import 'package:altme/l10n/l10n.dart'; import 'package:flutter/material.dart'; @@ -62,30 +63,9 @@ class HomeCredentialCategoryItem extends StatelessWidget { horizontal: 4, vertical: 0, ), - child: GridView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - crossAxisSpacing: 14, - mainAxisSpacing: 14, - childAspectRatio: Sizes.credentialAspectRatio, - ), - itemCount: sortedCredentials.length + 1, - itemBuilder: (_, index) { - if (index == sortedCredentials.length) { - if (credentialCategory == CredentialCategory.pendingCards) { - return Container(); - } - return AddCredentialButton( - credentialCategory: credentialCategory, - ); - } else { - return HomeCredentialItem( - credentialModel: sortedCredentials[index], - ); - } - }, + child: CredentialListWidget( + sortedCredentials: sortedCredentials, + credentialCategory: credentialCategory, ), ), ], diff --git a/pubspec.lock b/pubspec.lock index cb5c2b61d..3e316d38a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -370,6 +370,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.2" + card_swiper: + dependency: "direct main" + description: + name: card_swiper + sha256: "21e52a144decbf0054e7cfed8bbe46fc89635e6c86b767eaccfe7d5aeba32528" + url: "https://pub.dev" + source: hosted + version: "3.0.1" characters: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c82c63a04..549079fa7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: bloc: ^8.1.2 cached_network_image: ^3.2.3 camera: ^0.10.5+2 + card_swiper : ^3.0.0 confetti: ^0.7.0 connectivity_plus: ^5.0.2 convert: ^3.1.1