| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import 'package:flutter/material.dart';
- import 'package:physigo/Services/AuthService.dart';
- import 'package:physigo/challenge/services/challenge_service.dart';
- import 'package:physigo/challenge/widgets/challenge_exercises.dart';
- import 'package:physigo/navigation/navigation_page.dart';
- class WeeklyChallengePage extends StatelessWidget {
- const WeeklyChallengePage({Key? key}) : super(key: key);
- Future<dynamic> get weeklyPlaceFuture => AuthenticationServices.user!.weeklyPlace.get();
- @override
- Widget build(BuildContext context) {
- return FutureBuilder<dynamic>(
- future: weeklyPlaceFuture,
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.waiting) {
- return const Center(child: CircularProgressIndicator());
- }
- final weeklyPlace = snapshot.data.data();
- final weeklyPlaceName = weeklyPlace["name"];
- final weeklyPlaceLocation = weeklyPlace["location"]["geopoint"];
- return Scaffold(
- body: Padding(
- padding: const EdgeInsets.all(16.0),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- const Center(
- child: Text(
- "Weekly Challenge",
- textAlign: TextAlign.center,
- style: TextStyle(
- fontSize: 28,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- const SizedBox(height: 12),
- Center(
- child: Text(
- "Location: $weeklyPlaceName",
- textAlign: TextAlign.center,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(fontSize: 18),
- ),
- ),
- const SizedBox(height: 48),
- const ChallengeExercises(getChallenge: ChallengeService.getWeeklyChallenge),
- const SizedBox(height: 48),
- NavigationButton(weeklyPlaceLocation: weeklyPlaceLocation),
- ],
- ),
- ),
- );
- });
- }
- }
- class NavigationButton extends StatelessWidget {
- const NavigationButton({
- Key? key,
- required this.weeklyPlaceLocation,
- }) : super(key: key);
- final dynamic weeklyPlaceLocation;
- @override
- Widget build(BuildContext context) {
- return ElevatedButton(
- style: ElevatedButton.styleFrom(primary: Colors.teal),
- onPressed: () => Navigator.push(
- context,
- MaterialPageRoute(
- builder: (_) => NavigationPage(destination: weeklyPlaceLocation),
- ),
- ),
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: const [
- Flexible(child: Text("Show me the way", style: TextStyle(fontSize: 24), maxLines: 2)),
- Icon(Icons.map, size: 32),
- ],
- ),
- ),
- );
- }
- }
|