139 lines
4.2 KiB
Dart
139 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../services/network_group_service.dart';
|
|
|
|
class NetworkDemoWidget extends StatefulWidget {
|
|
final NetworkGroupService networkService;
|
|
|
|
const NetworkDemoWidget({
|
|
super.key,
|
|
required this.networkService,
|
|
});
|
|
|
|
@override
|
|
State<NetworkDemoWidget> createState() => _NetworkDemoWidgetState();
|
|
}
|
|
|
|
class _NetworkDemoWidgetState extends State<NetworkDemoWidget> {
|
|
bool _isDemoMode = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF2D2D2D),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: const Color(0xFF6366F1), width: 1),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
const Icon(
|
|
Icons.developer_mode,
|
|
color: Color(0xFF6366F1),
|
|
size: 20,
|
|
),
|
|
const SizedBox(width: 8),
|
|
const Text(
|
|
'Demo Mode',
|
|
style: TextStyle(
|
|
color: Color(0xFF6366F1),
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Switch(
|
|
value: _isDemoMode,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_isDemoMode = value;
|
|
});
|
|
_toggleDemoMode(value);
|
|
},
|
|
activeColor: const Color(0xFF6366F1),
|
|
),
|
|
],
|
|
),
|
|
if (_isDemoMode) ...[
|
|
const SizedBox(height: 12),
|
|
const Text(
|
|
'Demo mode simulates network connectivity and adds sample users for testing.',
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed: _addDemoUser,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF6366F1).withOpacity(0.2),
|
|
foregroundColor: const Color(0xFF6366F1),
|
|
elevation: 0,
|
|
),
|
|
child: const Text('Add Demo User'),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
onPressed: _simulateVote,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF22C55E).withOpacity(0.2),
|
|
foregroundColor: const Color(0xFF22C55E),
|
|
elevation: 0,
|
|
),
|
|
child: const Text('Simulate Vote'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _toggleDemoMode(bool enabled) {
|
|
if (enabled) {
|
|
// Simulate network connection
|
|
widget.networkService.simulateNetworkConnection();
|
|
_addInitialDemoUsers();
|
|
} else {
|
|
// Clear demo users
|
|
widget.networkService.clearDemoUsers();
|
|
}
|
|
}
|
|
|
|
void _addInitialDemoUsers() {
|
|
final demoUsers = [
|
|
{'name': 'Alex M.', 'votes': 5},
|
|
{'name': 'Sarah K.', 'votes': 3},
|
|
{'name': 'Marco R.', 'votes': 7},
|
|
{'name': 'Lisa F.', 'votes': 2},
|
|
];
|
|
|
|
for (var user in demoUsers) {
|
|
widget.networkService.addDemoUser(user['name'] as String, user['votes'] as int);
|
|
}
|
|
}
|
|
|
|
void _addDemoUser() {
|
|
final names = ['Tom B.', 'Emma W.', 'David L.', 'Anna K.', 'Mike R.', 'Julia S.'];
|
|
final randomName = names[DateTime.now().millisecond % names.length];
|
|
final randomVotes = (DateTime.now().millisecond % 10) + 1;
|
|
|
|
widget.networkService.addDemoUser(randomName, randomVotes);
|
|
}
|
|
|
|
void _simulateVote() {
|
|
widget.networkService.updateUserVotes(widget.networkService.currentUser.votes + 1);
|
|
}
|
|
}
|