proxybuy-flutter/lib/screens/mains/hunt/examples/hunt_usage_examples.dart

239 lines
7.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:lba/screens/mains/hunt/hunt.dart';
import 'package:lba/screens/mains/hunt/providers/hunt_provider.dart';
import 'package:lba/screens/mains/hunt/models/hunt_card.dart';
import 'package:lba/screens/mains/hunt/widgets/hunt_card_widget.dart';
import 'package:lba/screens/mains/hunt/widgets/leaderboard_widget.dart';
class ExampleHuntIntegration extends StatelessWidget {
const ExampleHuntIntegration({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => HuntState()..initializeGame(),
child: const Hunt(),
);
}
}
class ExampleHuntCard extends StatelessWidget {
const ExampleHuntCard({super.key});
@override
Widget build(BuildContext context) {
final exampleCard = HuntCard(
id: 'example_1',
category: 'Coffee Shop',
categoryIcon: '',
points: 150,
question: 'Where coffee meets books in perfect harmony...',
answer: 'Literary Café',
description: 'A cozy bookstore café',
targetLatitude: 32.62503845297132,
targetLongitude: 51.72643744503593,
hintLatitude: 32.62503845297132,
hintLongitude: 51.72643744503593,
hintDescription: 'Look for the AR marker near the entrance',
);
return Scaffold(
body: Center(
child: HuntCardWidget(
card: exampleCard,
onTap: () {
print('Card ${exampleCard.id} selected!');
},
isSelected: false,
isFlipped: false,
),
),
);
}
}
class ExampleLeaderboard extends StatelessWidget {
const ExampleLeaderboard({super.key});
@override
Widget build(BuildContext context) {
final mockLeaderboard = [
const LeaderboardEntry(
id: '1',
name: 'John Doe',
avatar: '🏆',
totalPoints: 850,
rank: 1,
),
const LeaderboardEntry(
id: '2',
name: 'Jane Smith',
avatar: '🥈',
totalPoints: 720,
rank: 2,
),
const LeaderboardEntry(
id: 'current',
name: 'You',
avatar: '👤',
totalPoints: 450,
rank: 3,
isCurrentUser: true,
),
];
return Scaffold(
body: LeaderboardWidget(
entries: mockLeaderboard,
userPoints: 450,
onClose: () {
Navigator.of(context).pop();
},
),
);
}
}
class ExampleHuntStateUsage extends StatefulWidget {
const ExampleHuntStateUsage({super.key});
@override
State<ExampleHuntStateUsage> createState() => _ExampleHuntStateUsageState();
}
class _ExampleHuntStateUsageState extends State<ExampleHuntStateUsage> {
late HuntState huntState;
@override
void initState() {
super.initState();
huntState = HuntState();
huntState.initializeGame();
}
@override
void dispose() {
huntState.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(
value: huntState,
child: Scaffold(
appBar: AppBar(title: const Text('Hunt State Example')),
body: Consumer<HuntState>(
builder: (context, state, child) {
return Column(
children: [
Text('Current State: ${state.gameState}'),
Text('User Points: ${state.userPoints}'),
Text('Cards Available: ${state.cards.length}'),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
onPressed: state.cards.isEmpty
? null
: () => state.selectCard(state.cards.first),
child: const Text('Select First Card'),
),
ElevatedButton(
onPressed: state.gameState == HuntGameState.cardFlipped
? () => state.startHunt()
: null,
child: const Text('Start Hunt'),
),
ElevatedButton(
onPressed: state.gameState == HuntGameState.huntingActive
? () => state.completeHunt()
: null,
child: const Text('Complete Hunt'),
),
],
),
if (state.selectedCard != null) ...[
const SizedBox(height: 20),
Text('Selected Card: ${state.selectedCard!.category}'),
Text('Points: ${state.selectedCard!.points}'),
Text('Question: ${state.selectedCard!.question}'),
],
if (state.gameState == HuntGameState.huntingActive) ...[
const SizedBox(height: 20),
Text('Time Remaining: ${_formatDuration(state.timeRemaining)}'),
],
],
);
},
),
),
);
}
String _formatDuration(Duration duration) {
final hours = duration.inHours;
final minutes = duration.inMinutes % 60;
final seconds = duration.inSeconds % 60;
return '${hours.toString().padLeft(2, '0')}:'
'${minutes.toString().padLeft(2, '0')}:'
'${seconds.toString().padLeft(2, '0')}';
}
}
class ExampleHuntNavigation extends StatelessWidget {
const ExampleHuntNavigation({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Hunt Navigation Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ChangeNotifierProvider(
create: (_) => HuntState()..initializeGame(),
child: const Hunt(),
),
),
);
},
child: const Text('Start Treasure Hunt'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ExampleLeaderboard(),
),
);
},
child: const Text('View Leaderboard'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ExampleHuntCard(),
),
);
},
child: const Text('Preview Hunt Card'),
),
],
),
),
);
}
}