cashumit/lib/widgets/store_info_widget.dart

98 lines
3.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:io';
import 'package:intl/intl.dart';
/// Widget untuk menampilkan informasi toko dan admin
/// Dapat di-tap untuk membuka dialog konfigurasi
class StoreInfoWidget extends StatefulWidget {
final VoidCallback onTap; // Callback ketika widget di-tap
const StoreInfoWidget({super.key, required this.onTap});
@override
State<StoreInfoWidget> createState() => _StoreInfoWidgetState();
}
class _StoreInfoWidgetState extends State<StoreInfoWidget> {
String storeName = 'TOKO SEMBAKO MURAH';
String storeAddress = 'Jl. Merdeka No. 123';
String adminName = 'Budi Santoso';
String adminPhone = '08123456789';
String? _logoPath; // Path to the store logo
@override
void initState() {
super.initState();
// _loadStoreInfo() will be called in build to ensure it's always up-to-date
}
/// Memuat informasi toko dari shared preferences
Future<void> _loadStoreInfo() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
storeName = prefs.getString('store_name') ?? 'TOKO SEMBAKO MURAH';
storeAddress = prefs.getString('store_address') ?? 'Jl. Merdeka No. 123';
adminName = prefs.getString('admin_name') ?? 'Budi Santoso';
adminPhone = prefs.getString('admin_phone') ?? '08123456789';
_logoPath = prefs.getString('store_logo_path'); // Load logo path
});
}
@override
Widget build(BuildContext context) {
// Load data every time the widget is built to ensure it's up-to-date
_loadStoreInfo();
final courierPrime = GoogleFonts.courierPrime(
textStyle: const TextStyle(
fontSize: 14,
height: 1.2,
),
);
return GestureDetector(
onTap: widget.onTap, // Panggil callback ketika di-tap
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(8.0),
color: Colors.white,
child: Column(
children: [
// Display store logo if available
if (_logoPath != null && _logoPath!.isNotEmpty)
Container(
margin: const EdgeInsets.only(bottom: 8.0),
child: Image.file(
File(_logoPath!),
height: 60,
width: 60,
fit: BoxFit.contain,
),
),
Text(
storeName,
style: courierPrime.copyWith(
fontSize: 16,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
Text(storeAddress, style: courierPrime, textAlign: TextAlign.center),
const SizedBox(height: 4),
Text('Admin: $adminName', style: courierPrime, textAlign: TextAlign.center),
Text('Telp: $adminPhone', style: courierPrime, textAlign: TextAlign.center),
const SizedBox(height: 4),
Text('Tanggal: ${DateFormat('dd/MM/yyyy').format(DateTime.now())}',
style: courierPrime,
textAlign: TextAlign.center),
],
),
),
);
}
}