Skip to content

Commit

Permalink
add card_swiper and basic configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Oct 10, 2024
1 parent 935608e commit a14891c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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<CredentialModel> 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<CredentialModel> 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<CredentialModel> 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(),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
),
),
],
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a14891c

Please sign in to comment.