111 lines
3.7 KiB
Dart
111 lines
3.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../services/odoo_service.dart';
|
|
|
|
class LoyaltyDashboard extends StatefulWidget {
|
|
final int partnerId;
|
|
|
|
const LoyaltyDashboard({super.key, required this.partnerId});
|
|
|
|
@override
|
|
State<LoyaltyDashboard> createState() => _LoyaltyDashboardState();
|
|
}
|
|
|
|
class _LoyaltyDashboardState extends State<LoyaltyDashboard> {
|
|
List<dynamic> _loyaltyCards = [];
|
|
bool _isLoading = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_fetchLoyaltyData();
|
|
}
|
|
|
|
Future<void> _fetchLoyaltyData() async {
|
|
try {
|
|
final cards = await OdooService().getLoyaltyCards(widget.partnerId);
|
|
setState(() {
|
|
_loyaltyCards = cards;
|
|
_isLoading = false;
|
|
});
|
|
} catch (e) {
|
|
setState(() => _isLoading = false);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Error loading loyalty cards: $e')),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('My Loyalty Programs'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.refresh),
|
|
onPressed: () {
|
|
setState(() => _isLoading = true);
|
|
_fetchLoyaltyData();
|
|
},
|
|
)
|
|
],
|
|
),
|
|
body: _isLoading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: _loyaltyCards.isEmpty
|
|
? const Center(
|
|
child: Text(
|
|
'No loyalty cards found.',
|
|
style: TextStyle(fontSize: 18),
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.all(12),
|
|
itemCount: _loyaltyCards.length,
|
|
itemBuilder: (context, index) {
|
|
final card = _loyaltyCards[index];
|
|
return Card(
|
|
elevation: 4,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
margin: const EdgeInsets.symmetric(vertical: 8.0),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'${card['program_id']?[1] ?? 'Loyalty Program'}',
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text('Code: ${card['code'] ?? 'N/A'}'),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
const Text('Points Available:'),
|
|
Text(
|
|
'${card['points'] ?? 0} pts',
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 20,
|
|
color: Colors.green,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|