EnakPoint & EnakCoin wallet, PIN, outlet, order, community, reward
- Wallet EnakPoint & EnakCoin: beranda, riwayat, saldo kedaluwarsa, kode bayar, tukar EnakCoin, transfer - PIN (buat, ganti, lupa), outlet, riwayat order, game spin - Halaman community, webview, coming soon, dan ikon menu beranda baru - Redesign Reward Saya: kartu tiket, filter chip, detail kode + QR - Hapus customer point loader, menu, dan checkout lama - Base URL ke enaklo-pos-api.altru.id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5954510b93
commit
f5e3075205
@@ -2,62 +2,31 @@ import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../sample/reward_sample_data.dart';
|
||||
import '../../components/assets/assets.gen.dart';
|
||||
import '../../router/app_router.gr.dart';
|
||||
import 'reward_ui.dart';
|
||||
import 'widgets/reward_card.dart';
|
||||
import 'widgets/reward_detail_sheet.dart';
|
||||
|
||||
// Models
|
||||
class Reward {
|
||||
final String id;
|
||||
final String name;
|
||||
final String image;
|
||||
final int pointsUsed;
|
||||
final String description;
|
||||
final DateTime redeemedAt;
|
||||
final RewardStatus status;
|
||||
final String? couponCode;
|
||||
final String? validUntil;
|
||||
final String? termsAndConditions;
|
||||
final String categoryName;
|
||||
final String categoryIcon;
|
||||
enum _RewardFilter {
|
||||
all('Semua'),
|
||||
active('Aktif'),
|
||||
used('Terpakai'),
|
||||
expired('Kedaluwarsa');
|
||||
|
||||
Reward({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.image,
|
||||
required this.pointsUsed,
|
||||
required this.description,
|
||||
required this.redeemedAt,
|
||||
required this.status,
|
||||
required this.categoryName,
|
||||
required this.categoryIcon,
|
||||
this.couponCode,
|
||||
this.validUntil,
|
||||
this.termsAndConditions,
|
||||
});
|
||||
const _RewardFilter(this.label);
|
||||
|
||||
String get statusText {
|
||||
switch (status) {
|
||||
case RewardStatus.active:
|
||||
return "Aktif";
|
||||
case RewardStatus.used:
|
||||
return "Sudah Digunakan";
|
||||
case RewardStatus.expired:
|
||||
return "Kadaluarsa";
|
||||
}
|
||||
}
|
||||
final String label;
|
||||
|
||||
Color get statusColor {
|
||||
switch (status) {
|
||||
case RewardStatus.active:
|
||||
return AppColor.success;
|
||||
case RewardStatus.used:
|
||||
return AppColor.textSecondary;
|
||||
case RewardStatus.expired:
|
||||
return AppColor.error;
|
||||
}
|
||||
}
|
||||
bool matches(Reward reward) => switch (this) {
|
||||
_RewardFilter.all => true,
|
||||
_RewardFilter.active => reward.status == RewardStatus.active,
|
||||
_RewardFilter.used => reward.status == RewardStatus.used,
|
||||
_RewardFilter.expired => reward.status == RewardStatus.expired,
|
||||
};
|
||||
}
|
||||
|
||||
enum RewardStatus { active, used, expired }
|
||||
|
||||
@RoutePage()
|
||||
class RewardPage extends StatefulWidget {
|
||||
const RewardPage({super.key});
|
||||
@@ -66,350 +35,368 @@ class RewardPage extends StatefulWidget {
|
||||
State<RewardPage> createState() => _RewardPageState();
|
||||
}
|
||||
|
||||
class _RewardPageState extends State<RewardPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
class _RewardPageState extends State<RewardPage> {
|
||||
_RewardFilter _filter = _RewardFilter.all;
|
||||
|
||||
// Sample reward data
|
||||
final List<Reward> rewards = [
|
||||
Reward(
|
||||
id: "r1",
|
||||
name: "Es Teh Manis",
|
||||
image: "🧊",
|
||||
pointsUsed: 1500,
|
||||
description: "Teh manis dingin segar",
|
||||
redeemedAt: DateTime.now().subtract(Duration(hours: 2)),
|
||||
status: RewardStatus.active,
|
||||
categoryName: "Minuman",
|
||||
categoryIcon: "🥤",
|
||||
couponCode: "ETM123456",
|
||||
validUntil: "31 Des 2025",
|
||||
termsAndConditions:
|
||||
"Berlaku untuk dine-in dan take away. Tidak dapat digabung dengan promo lain.",
|
||||
),
|
||||
Reward(
|
||||
id: "r2",
|
||||
name: "Diskon 50%",
|
||||
image: "🏷️",
|
||||
pointsUsed: 5000,
|
||||
description: "Potongan harga 50% untuk semua menu",
|
||||
redeemedAt: DateTime.now().subtract(Duration(days: 1)),
|
||||
status: RewardStatus.used,
|
||||
categoryName: "Voucher",
|
||||
categoryIcon: "🎟️",
|
||||
couponCode: "DISC50789",
|
||||
validUntil: "15 Des 2025",
|
||||
termsAndConditions:
|
||||
"Berlaku untuk pembelian minimum Rp 50.000. Tidak berlaku untuk menu promo.",
|
||||
),
|
||||
Reward(
|
||||
id: "r3",
|
||||
name: "Nasi Gudeg",
|
||||
image: "🍛",
|
||||
pointsUsed: 4000,
|
||||
description: "Gudeg Jogja autentik",
|
||||
redeemedAt: DateTime.now().subtract(Duration(days: 3)),
|
||||
status: RewardStatus.active,
|
||||
categoryName: "Makanan",
|
||||
categoryIcon: "🍽️",
|
||||
couponCode: "GUDEG456",
|
||||
validUntil: "25 Des 2025",
|
||||
termsAndConditions:
|
||||
"Berlaku untuk 1 porsi. Dapat dimakan di tempat atau dibawa pulang.",
|
||||
),
|
||||
Reward(
|
||||
id: "r4",
|
||||
name: "Gratis Ongkir",
|
||||
image: "🚚",
|
||||
pointsUsed: 2000,
|
||||
description: "Bebas ongkos kirim untuk pesanan apapun",
|
||||
redeemedAt: DateTime.now().subtract(Duration(days: 15)),
|
||||
status: RewardStatus.expired,
|
||||
categoryName: "Voucher",
|
||||
categoryIcon: "🎟️",
|
||||
validUntil: "20 Agu 2025",
|
||||
termsAndConditions:
|
||||
"Berlaku untuk area Jabodetabek. Minimum pembelian Rp 25.000.",
|
||||
),
|
||||
Reward(
|
||||
id: "r5",
|
||||
name: "Kopi Susu",
|
||||
image: "☕",
|
||||
pointsUsed: 2000,
|
||||
description: "Kopi dengan susu creamy",
|
||||
redeemedAt: DateTime.now().subtract(Duration(days: 7)),
|
||||
status: RewardStatus.used,
|
||||
categoryName: "Minuman",
|
||||
categoryIcon: "🥤",
|
||||
couponCode: "KOPI987654",
|
||||
validUntil: "30 Nov 2025",
|
||||
termsAndConditions:
|
||||
"Berlaku untuk size regular. Dapat request level manis.",
|
||||
),
|
||||
];
|
||||
/// Aktif lebih dulu, urut yang paling cepat berakhir; sisanya terbaru dulu.
|
||||
final List<Reward> _rewards = [...rewardSamples]
|
||||
..sort((a, b) {
|
||||
final aActive = a.status == RewardStatus.active;
|
||||
final bActive = b.status == RewardStatus.active;
|
||||
if (aActive != bActive) return aActive ? -1 : 1;
|
||||
if (aActive) return a.validUntil.compareTo(b.validUntil);
|
||||
return b.redeemedAt.compareTo(a.redeemedAt);
|
||||
});
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 4, vsync: this);
|
||||
}
|
||||
List<Reward> get _activeRewards =>
|
||||
_rewards.where(_RewardFilter.active.matches).toList();
|
||||
|
||||
List<Reward> get filteredRewards {
|
||||
switch (_tabController.index) {
|
||||
case 0:
|
||||
return rewards; // Semua
|
||||
case 1:
|
||||
return rewards.where((r) => r.status == RewardStatus.active).toList();
|
||||
case 2:
|
||||
return rewards.where((r) => r.status == RewardStatus.used).toList();
|
||||
case 3:
|
||||
return rewards.where((r) => r.status == RewardStatus.expired).toList();
|
||||
default:
|
||||
return rewards;
|
||||
}
|
||||
}
|
||||
int _countOf(_RewardFilter filter) => _rewards.where(filter.matches).length;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final visible = _rewards.where(_filter.matches).toList();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.backgroundLight,
|
||||
appBar: AppBar(title: Text("Reward Saya"), centerTitle: true),
|
||||
body: Column(
|
||||
children: [
|
||||
_buildCleanTabBar(),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildRewardList(), // Semua
|
||||
_buildRewardList(), // Aktif
|
||||
_buildRewardList(), // Digunakan
|
||||
_buildRewardList(), // Kadaluarsa
|
||||
],
|
||||
backgroundColor: AppColor.background,
|
||||
appBar: AppBar(title: const Text('Reward Saya')),
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: _buildSummary()),
|
||||
SliverPersistentHeader(
|
||||
pinned: true,
|
||||
delegate: _FilterHeaderDelegate(
|
||||
selected: _filter,
|
||||
countOf: _countOf,
|
||||
onSelected: (filter) => setState(() => _filter = filter),
|
||||
),
|
||||
),
|
||||
if (visible.isEmpty)
|
||||
SliverFillRemaining(hasScrollBody: false, child: _buildEmpty())
|
||||
else
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 32),
|
||||
sliver: SliverList.separated(
|
||||
itemCount: visible.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) {
|
||||
final reward = visible[index];
|
||||
return RewardCard(
|
||||
reward: reward,
|
||||
onTap: () => RewardDetailSheet.show(context, reward),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCleanTabBar() {
|
||||
final activeCount = rewards
|
||||
.where((r) => r.status == RewardStatus.active)
|
||||
.length;
|
||||
final usedCount = rewards
|
||||
.where((r) => r.status == RewardStatus.used)
|
||||
.length;
|
||||
final expiredCount = rewards
|
||||
.where((r) => r.status == RewardStatus.expired)
|
||||
.length;
|
||||
Widget _buildSummary() {
|
||||
final active = _activeRewards;
|
||||
// Sudah terurut: yang pertama adalah yang paling cepat berakhir.
|
||||
final expiringSoon = active.where(isRewardExpiringSoon).firstOrNull;
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
margin: const EdgeInsets.fromLTRB(16, 16, 16, 4),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
gradient: const LinearGradient(
|
||||
colors: AppColor.primaryGradient,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 20,
|
||||
offset: Offset(0, 4),
|
||||
color: AppColor.primary.withOpacity(0.3),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
dividerColor: Colors.transparent,
|
||||
onTap: (index) => setState(() {}),
|
||||
tabs: [
|
||||
_buildCleanTab("Semua", rewards.length),
|
||||
_buildCleanTab("Aktif", activeCount),
|
||||
_buildCleanTab("Terpakai", usedCount),
|
||||
_buildCleanTab("Expired", expiredCount),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCleanTab(String label, int count) {
|
||||
return Container(height: 44, child: Center(child: Text("$label ($count)")));
|
||||
}
|
||||
|
||||
Widget _buildRewardList() {
|
||||
final filteredData = filteredRewards;
|
||||
|
||||
if (filteredData.isEmpty) {
|
||||
return _buildEmptyState();
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
itemCount: filteredData.length,
|
||||
itemBuilder: (context, index) {
|
||||
final reward = filteredData[index];
|
||||
return _buildCleanRewardCard(reward);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
String message;
|
||||
String icon;
|
||||
|
||||
switch (_tabController.index) {
|
||||
case 1:
|
||||
message = "Belum ada reward aktif";
|
||||
icon = "🎯";
|
||||
break;
|
||||
case 2:
|
||||
message = "Belum ada reward yang digunakan";
|
||||
icon = "✅";
|
||||
break;
|
||||
case 3:
|
||||
message = "Tidak ada reward yang kadaluarsa";
|
||||
icon = "⏰";
|
||||
break;
|
||||
default:
|
||||
message = "Belum ada reward";
|
||||
icon = "🎁";
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(icon, style: TextStyle(fontSize: 64)),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
message,
|
||||
style: AppStyle.lg.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
"Tukar poin Anda untuk mendapatkan reward menarik",
|
||||
style: AppStyle.sm.copyWith(color: AppColor.textLight),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: () => context.router.back(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColor.primary,
|
||||
foregroundColor: AppColor.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
elevation: 0,
|
||||
),
|
||||
child: Text(
|
||||
"Tukar Poin Sekarang",
|
||||
style: AppStyle.sm.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCleanRewardCard(Reward reward) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 20,
|
||||
offset: Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Row(
|
||||
Row(
|
||||
children: [
|
||||
// Product Image - Simplified
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.backgroundLight,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
width: 48,
|
||||
height: 48,
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColor.white,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(reward.image, style: TextStyle(fontSize: 24)),
|
||||
child: Assets.icons.enakrewardIcon.image(
|
||||
fit: BoxFit.contain,
|
||||
// Aset aslinya besar; decode seukuran tampilan saja.
|
||||
cacheWidth: (32 * MediaQuery.devicePixelRatioOf(context))
|
||||
.round(),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 16),
|
||||
|
||||
// Reward Info - Cleaner layout
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
reward.name,
|
||||
style: AppStyle.md.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildStatusBadge(reward),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
reward.description,
|
||||
'Siap dipakai',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
color: AppColor.textWhite.withOpacity(0.9),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
size: 12,
|
||||
color: AppColor.textLight,
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'${active.length} reward',
|
||||
style: AppStyle.h5.copyWith(
|
||||
color: AppColor.textWhite,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
_formatDate(reward.redeemedAt),
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textLight,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Icon(Icons.stars, size: 14, color: AppColor.warning),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
"${reward.pointsUsed}",
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: AppColor.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Material(
|
||||
color: AppColor.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
onTap: () => context.router.push(const CoinRoute()),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 8,
|
||||
),
|
||||
child: Text(
|
||||
'Tukar Poin',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.primary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (expiringSoon != null) ...[
|
||||
const SizedBox(height: 14),
|
||||
Material(
|
||||
color: AppColor.white.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: () => RewardDetailSheet.show(context, expiringSoon),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.schedule,
|
||||
size: 16,
|
||||
color: AppColor.textWhite,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${expiringSoon.name} · '
|
||||
'${rewardValidityLabel(expiringSoon).toLowerCase()}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textWhite,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
size: 18,
|
||||
color: AppColor.textWhite,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmpty() {
|
||||
final (String emoji, String message) = switch (_filter) {
|
||||
_RewardFilter.all => ('🎁', 'Belum ada reward'),
|
||||
_RewardFilter.active => ('🎯', 'Belum ada reward aktif'),
|
||||
_RewardFilter.used => ('✅', 'Belum ada reward yang dipakai'),
|
||||
_RewardFilter.expired => ('⏰', 'Tidak ada reward yang kedaluwarsa'),
|
||||
};
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(32, 32, 32, 64),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 96,
|
||||
height: 96,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.primary.withOpacity(0.06),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Text(emoji, style: const TextStyle(fontSize: 44)),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
message,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.lg.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'Tukar poin kamu untuk mendapatkan reward menarik',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.sm.copyWith(color: AppColor.textSecondary),
|
||||
),
|
||||
if (_filter == _RewardFilter.all ||
|
||||
_filter == _RewardFilter.active) ...[
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () => context.router.push(const CoinRoute()),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'Tukar Poin Sekarang',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FilterHeaderDelegate extends SliverPersistentHeaderDelegate {
|
||||
_FilterHeaderDelegate({
|
||||
required this.selected,
|
||||
required this.countOf,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final _RewardFilter selected;
|
||||
final int Function(_RewardFilter) countOf;
|
||||
final ValueChanged<_RewardFilter> onSelected;
|
||||
|
||||
static const double _height = 56;
|
||||
|
||||
@override
|
||||
double get minExtent => _height;
|
||||
|
||||
@override
|
||||
double get maxExtent => _height;
|
||||
|
||||
@override
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
double shrinkOffset,
|
||||
bool overlapsContent,
|
||||
) {
|
||||
return Container(
|
||||
color: AppColor.background,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
itemCount: _RewardFilter.values.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final filter = _RewardFilter.values[index];
|
||||
return _FilterChip(
|
||||
label: filter.label,
|
||||
count: countOf(filter),
|
||||
isSelected: filter == selected,
|
||||
onTap: () => onSelected(filter),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRebuild(covariant _FilterHeaderDelegate oldDelegate) =>
|
||||
oldDelegate.selected != selected;
|
||||
}
|
||||
|
||||
class _FilterChip extends StatelessWidget {
|
||||
const _FilterChip({
|
||||
required this.label,
|
||||
required this.count,
|
||||
required this.isSelected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final int count;
|
||||
final bool isSelected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final foreground = isSelected ? AppColor.textWhite : AppColor.textPrimary;
|
||||
|
||||
return Material(
|
||||
color: isSelected ? AppColor.primary : AppColor.white,
|
||||
shape: StadiumBorder(
|
||||
side: BorderSide(
|
||||
color: isSelected ? AppColor.primary : AppColor.border,
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
customBorder: const StadiumBorder(),
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: foreground,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColor.white.withOpacity(0.2)
|
||||
: AppColor.primary.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'$count',
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: isSelected ? AppColor.textWhite : AppColor.primary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -418,61 +405,4 @@ class _RewardPageState extends State<RewardPage>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusBadge(Reward reward) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: reward.statusColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
reward.statusText,
|
||||
style: AppStyle.xs.copyWith(
|
||||
color: reward.statusColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
final months = [
|
||||
'',
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'Mei',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Agu',
|
||||
'Sep',
|
||||
'Okt',
|
||||
'Nov',
|
||||
'Des',
|
||||
];
|
||||
|
||||
final now = DateTime.now();
|
||||
final difference = now.difference(date);
|
||||
|
||||
if (difference.inDays == 0) {
|
||||
if (difference.inHours == 0) {
|
||||
return "${difference.inMinutes} menit lalu";
|
||||
}
|
||||
return "${difference.inHours} jam lalu";
|
||||
} else if (difference.inDays == 1) {
|
||||
return "Kemarin";
|
||||
} else if (difference.inDays < 7) {
|
||||
return "${difference.inDays} hari lalu";
|
||||
} else {
|
||||
return "${date.day} ${months[date.month]} ${date.year}";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user