ironing out erp bugs

This commit is contained in:
2025-09-27 01:09:05 +02:00
parent cbabff4c10
commit f1e2327732
41 changed files with 1440 additions and 516 deletions

View File

@@ -280,7 +280,7 @@ class HomeController extends ChangeNotifier {
description: 'USD Wallet',
image: 'united-states.png',
currency: 'USD',
balance: '4.02',
balance: '47655.02',
),
Account(
name: 'Vusumuzi Khoza',

View File

@@ -21,13 +21,12 @@ class _HomeScreenState extends State<HomeScreen>
late AnimationController _controller;
late Animation<AlignmentGeometry> _alignAnimation;
late TransactionController transactionController;
late bool _loading = true;
late SharedPreferences prefs;
late HomeController homeController;
late final router = GoRouter.of(context);
late String initials;
Timer? _loadingTimer;
bool get _isLoggedIn => false;
bool _isLoggedIn = false;
String _selectedFilter = 'All';
final List<Animation<Offset>> _animations = [];
@@ -36,15 +35,6 @@ class _HomeScreenState extends State<HomeScreen>
@override
void initState() {
super.initState();
router.routerDelegate.addListener(_onRouteChanged);
transactionController = Provider.of<TransactionController>(
context,
listen: false,
);
// Reset the transaction controller model
transactionController.model = TransactionModel();
_controller = AnimationController(
duration: const Duration(milliseconds: 600),
@@ -69,18 +59,19 @@ class _HomeScreenState extends State<HomeScreen>
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOut));
setupDataAndTransitions();
// Simulate a delay to mimic loading state
_loadingTimer = Timer(const Duration(seconds: 1), () {
if (mounted) {
setState(() {
_loading = false;
});
}
});
}
Future<void> setupDataAndTransitions() async {
router.routerDelegate.addListener(_onRouteChanged);
transactionController = Provider.of<TransactionController>(
context,
listen: false,
);
// Reset the transaction controller model
transactionController.model = TransactionModel();
homeController = HomeController(context);
await homeController.getAccounts();
await homeController.getCategories();
@@ -103,8 +94,11 @@ class _HomeScreenState extends State<HomeScreen>
prefs = await SharedPreferences.getInstance();
if (prefs.getString("userId") == null) {
prefs.setString("userId", Uuid().v4());
if (prefs.getString("token") != null) {
setState(() {
_isLoggedIn = true;
initials = prefs.getString("initials")!;
});
}
await homeController.getTransactions(prefs.getString("userId")!);
@@ -126,16 +120,21 @@ class _HomeScreenState extends State<HomeScreen>
);
}
void _onRouteChanged() {
void _onRouteChanged() async {
final location = router.routerDelegate.currentConfiguration.uri.toString();
if (location.startsWith('/home')) {
setupDataAndTransitions();
prefs = await SharedPreferences.getInstance();
if (prefs.getString("userId") == null) {
prefs.setString("userId", Uuid().v4());
}
await homeController.getTransactions(prefs.getString("userId")!);
}
}
@override
void dispose() {
_loadingTimer?.cancel();
_controller.dispose();
homeController.dispose();
router.routerDelegate.removeListener(_onRouteChanged);
@@ -159,45 +158,83 @@ class _HomeScreenState extends State<HomeScreen>
surfaceTintColor: Colors.transparent,
floating: true,
title: Image(image: AssetImage('assets/peak.png'), width: 85),
leading: IconButton(
icon: Container(
width: 32,
height: 32,
decoration: BoxDecoration(
border: Border.all(color: Colors.black87.withAlpha(20)),
shape: BoxShape.circle,
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,
leading: _isLoggedIn ? Container(
padding: const EdgeInsets.only(left: 10.0),
child: IconButton(
icon: Container(
width: 52,
height: 52,
decoration: BoxDecoration(
border: Border.all(color: Colors.black87.withAlpha(20)),
shape: BoxShape.circle,
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,
),
),
),
child: Center(
child: Text(
'VK',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
child: Center(
child: Text(
initials,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
),
onPressed: () {},
),
onPressed: () {},
),
// actions: [
// IconButton(
// icon: const Icon(Icons.notifications_outlined),
// onPressed: () {},
// ),
// ],
) : SizedBox(),
actions: [
if(_isLoggedIn)
IconButton(
icon: const Icon(Icons.exit_to_app_sharp),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext dialogContext) {
return AlertDialog(
title: const Text('Confirm Logout'),
content: const Text('Are you sure you want to log out?'),
actions: <Widget>[
TextButton(
child: const Text('Cancel'),
onPressed: () {
Navigator.of(dialogContext).pop(); // Dismiss the dialog
},
),
TextButton(
child: const Text('Logout'),
onPressed: () {
Navigator.of(dialogContext).pop(); // Dismiss the dialog
prefs.remove("token");
setState(() {
_isLoggedIn = false;
});
// It's generally not recommended to call initState directly.
// Consider moving the logic from initState that needs to be rerun
// into a separate method and call that method here.
// For example, if you have a method like _reloadData(), call it here.
// _reloadData();
setupDataAndTransitions(); // Or specific parts of it if not all is needed
},
),
],
);
},
);
},
),
],
),
SliverToBoxAdapter(
child: Padding(
@@ -209,7 +246,7 @@ class _HomeScreenState extends State<HomeScreen>
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!_isLoggedIn) _buildLogin(homeController),
if (_isLoggedIn) _buildAccounts(homeController),
// if (_isLoggedIn) _buildAccounts(homeController),
_buildFilterChips(homeController),
SizedBox(height: 10),
Column(
@@ -361,7 +398,7 @@ class _HomeScreenState extends State<HomeScreen>
// context.push("/wallet");
},
child: Container(
width: 150,
width: 170,
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 12,
@@ -388,11 +425,11 @@ class _HomeScreenState extends State<HomeScreen>
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset('assets/${e.image}', width: 20),
SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset('assets/${e.image}', width: 20),
SizedBox(width: 10),
Text(
e.currency,
style: TextStyle(
@@ -402,12 +439,15 @@ class _HomeScreenState extends State<HomeScreen>
),
),
SizedBox(width: 5),
Text(
e.balance,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: Colors.black,
Expanded(
child: Text(
e.balance,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: Colors.black,
overflow: TextOverflow.ellipsis,
),
),
),
],