progress on home page

This commit is contained in:
2025-06-27 17:26:36 +02:00
parent a866d97b70
commit 03d0f77ac2
15 changed files with 929 additions and 279 deletions

View File

@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:qpay/screens/home/home_controller.dart';
import 'package:qpay/screens/pay/pay_controller.dart';
import 'package:skeletonizer/skeletonizer.dart';
import 'dart:async';
@@ -14,15 +16,15 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late final Animation<AlignmentGeometry> _alignAnimation;
late Animation<AlignmentGeometry> _alignAnimation;
final List<Animation<Offset>> _animations = [];
final List<Animation<Offset>> _alignListAnimations = [];
late final bool _enabled = true;
late bool _loading = true;
Timer? _loadingTimer;
bool get _isLoggedIn => true;
String _selectedFilter = 'All';
final HomeController homeController = HomeController();
@@ -31,6 +33,8 @@ class _HomeScreenState extends State<HomeScreen>
super.initState();
homeController.getCategories();
homeController.getProviders();
_controller = AnimationController(
duration: const Duration(milliseconds: 600),
vsync: this,
@@ -75,6 +79,35 @@ class _HomeScreenState extends State<HomeScreen>
});
}
getBoxDecoration(String? clientId) {
// BillProvider? provider = homeController.model.selectedProvider;
//
// if (provider != null && clientId != provider.clientId) {
// return BoxDecoration(
// border: Border.all(color: Colors.black87.withAlpha(20)),
// borderRadius: BorderRadius.circular(12),
// );
// }
return BoxDecoration(
// border: Border.all(
// color: Theme.of(context).colorScheme.primary.withValues(alpha: 0.7),
// width: 3,
// ),
border: Border.all(color: Colors.black87.withAlpha(20)),
borderRadius: BorderRadius.circular(12),
gradient: LinearGradient(
colors: [
Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
Theme.of(context).colorScheme.tertiary.withValues(alpha: 0.05),
],
stops: const [0.3, 0.7],
begin: Alignment.topRight,
end: Alignment.bottomLeft,
),
);
}
void _showErrorSnackBar(String? message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
@@ -84,14 +117,6 @@ class _HomeScreenState extends State<HomeScreen>
);
}
int _getCategoryIndex(String name) {
return homeController.model.categories.indexWhere((e) => e.name == name);
}
bool _isCategoryOdd(String name) {
return _getCategoryIndex(name) % 2 != 0;
}
@override
void dispose() {
_loadingTimer?.cancel();
@@ -101,7 +126,6 @@ class _HomeScreenState extends State<HomeScreen>
@override
Widget build(BuildContext context) {
final VoidCallback? onPressed = _enabled ? () {} : null;
return Scaffold(
body: SafeArea(
child: CustomScrollView(
@@ -119,204 +143,165 @@ class _HomeScreenState extends State<HomeScreen>
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_isLoggedIn)
AlignTransition(
alignment: _alignAnimation,
child: Skeletonizer(
enabled: _loading,
child: Column(
children: [
Text(
"Vusumuzi Khoza",
style: TextStyle(fontSize: 15),
child: ListenableBuilder(
listenable: homeController,
builder: (context, child) {
if (homeController.model.errorMessage != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_showErrorSnackBar(homeController.model.errorMessage);
});
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_isLoggedIn)
AlignTransition(
alignment: _alignAnimation,
child: Skeletonizer(
enabled: _loading,
child: Column(
children: [
Text(
"Vusumuzi Khoza",
style: TextStyle(fontSize: 15),
),
Text(
"USD 4.02",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 20),
],
),
Text(
"USD 4.02",
),
),
_buildFilterChips(homeController),
SizedBox(height: 10),
Column(
children: [
...homeController.model.filterableProviders.map(
(e) => _buildProviderItem(e, context),
),
],
),
SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Recent Activity',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
GestureDetector(
onTap: () {
context.go('/history');
},
child: const Text(
'View All',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
fontSize: 16,
fontWeight: FontWeight.normal,
),
),
const SizedBox(height: 20),
],
),
),
],
),
),
ListenableBuilder(
listenable: homeController,
builder: (context, child) {
if (homeController.model.errorMessage != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_showErrorSnackBar(
homeController.model.errorMessage,
);
});
}
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
...homeController.model.categories.map(
(e) => Skeletonizer(
enabled: homeController.model.isLoading,
child: SlideTransition(
position: _animations[0],
child: FilledButton(
style: ButtonStyle(
backgroundColor:
WidgetStateProperty.all(
_isCategoryOdd(e.name)
? Theme.of(context)
.colorScheme
.secondary
.withValues(alpha: 0.9)
: Theme.of(context)
.colorScheme
.primary
.withValues(alpha: 0.9),
),
padding: WidgetStateProperty.all(
const EdgeInsets.symmetric(
vertical: 17.5,
horizontal: 30,
),
),
),
onPressed: onPressed,
child: Row(
children: [
Icon(
Icons.electric_bolt,
color: Colors.white,
),
const SizedBox(width: 8),
Text(
e.name,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
const SizedBox(height: 20),
Skeletonizer(
enabled: _loading,
child: ListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: [
SlideTransition(
position: _alignListAnimations[0],
child: ListTile(
leading: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.primary
.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.electric_bolt,
color:
Theme.of(context).colorScheme.primary,
),
),
title: Text(
'Electricity Bill',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
'Paid USD 50.00',
style: TextStyle(
fontWeight: FontWeight.normal,
),
),
trailing: Text(
'-USD 50.00',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
],
),
homeController.model.categories.isNotEmpty
? const SizedBox(height: 30)
: SizedBox(),
],
);
},
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Recent Activity',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
GestureDetector(
onTap: () {
context.go('/history');
},
child: const Text(
'View All',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.normal,
),
),
SlideTransition(
position: _alignListAnimations[1],
child: ListTile(
leading: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.primary
.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.phone_android,
color:
Theme.of(context).colorScheme.primary,
),
),
title: Text(
'Airtime Purchase',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
'Purchased USD 10.00',
style: TextStyle(
fontWeight: FontWeight.normal,
),
),
trailing: Text(
'-USD 10.00',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
],
),
const SizedBox(height: 20),
Skeletonizer(
enabled: _loading,
child: ListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: [
SlideTransition(
position: _alignListAnimations[0],
child: ListTile(
leading: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.primary.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.electric_bolt,
color: Theme.of(context).colorScheme.primary,
),
),
title: Text(
'Electricity Bill',
style: TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(
'Paid USD 50.00',
style: TextStyle(fontWeight: FontWeight.normal),
),
trailing: Text(
'-USD 50.00',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
),
SlideTransition(
position: _alignListAnimations[1],
child: ListTile(
leading: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.primary.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.phone_android,
color: Theme.of(context).colorScheme.primary,
),
),
title: Text(
'Airtime Purchase',
style: TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(
'Purchased USD 10.00',
style: TextStyle(fontWeight: FontWeight.normal),
),
trailing: Text(
'-USD 10.00',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
],
);
},
),
),
),
@@ -325,4 +310,104 @@ class _HomeScreenState extends State<HomeScreen>
),
);
}
Column _buildProviderItem(BillProvider e, BuildContext context) {
return Column(
children: [
Skeletonizer(
enabled: homeController.model.isLoading,
child: SlideTransition(
position: _alignListAnimations[1],
child: Container(
decoration: getBoxDecoration(e.clientId),
child: InkWell(
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
onTap: () {
homeController.updateSelectedProvider(e);
context.go("/make-payment");
},
child: ListTile(
leading: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.primary.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Image(image: AssetImage("assets/${e.image}")),
),
title: Text(
e.name,
style: TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(
e.description,
style: TextStyle(fontWeight: FontWeight.normal, fontSize: 10),
),
trailing: Icon(
Icons.chevron_right,
color: Theme.of(
context,
).colorScheme.secondary.withValues(alpha: 0.7),
),
),
),
),
),
),
SizedBox(height: 10),
],
);
}
Widget _buildFilterChips(HomeController controller) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_buildFilterChip('All', controller),
...controller.model.categories.map((category) {
return _buildFilterChip(category.name, controller, category);
}),
],
),
);
}
Widget _buildFilterChip(
String label,
HomeController controller, [
Category? category,
]) {
final isSelected = _selectedFilter == label;
return Padding(
padding: const EdgeInsets.only(right: 8),
child: FilterChip(
selected: isSelected,
label: Text(label),
onSelected: (selected) {
setState(() {
_selectedFilter = label;
});
if (category != null) {
controller.updateSelectedCategory(category);
} else {
controller.updateSelectedCategory(null);
}
},
backgroundColor: Theme.of(context).colorScheme.surface,
selectedColor: Theme.of(context).colorScheme.primary.withOpacity(0.2),
checkmarkColor: Theme.of(context).colorScheme.primary,
labelStyle: TextStyle(
color:
isSelected
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface,
),
),
);
}
}