weekly_challenge_page.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'package:flutter/material.dart';
  2. import 'package:physigo/Services/AuthService.dart';
  3. import 'package:physigo/challenge/services/challenge_service.dart';
  4. import 'package:physigo/challenge/widgets/challenge_exercises.dart';
  5. import 'package:physigo/navigation/navigation_page.dart';
  6. class WeeklyChallengePage extends StatelessWidget {
  7. const WeeklyChallengePage({Key? key}) : super(key: key);
  8. Future<dynamic> get weeklyPlaceFuture => AuthenticationServices.user!.weeklyPlace.get();
  9. @override
  10. Widget build(BuildContext context) {
  11. return FutureBuilder<dynamic>(
  12. future: weeklyPlaceFuture,
  13. builder: (context, snapshot) {
  14. if (snapshot.connectionState == ConnectionState.waiting) {
  15. return const Center(child: CircularProgressIndicator());
  16. }
  17. final weeklyPlace = snapshot.data.data();
  18. final weeklyPlaceName = weeklyPlace["name"];
  19. final weeklyPlaceLocation = weeklyPlace["location"]["geopoint"];
  20. return Scaffold(
  21. body: Padding(
  22. padding: const EdgeInsets.all(16.0),
  23. child: Column(
  24. mainAxisAlignment: MainAxisAlignment.center,
  25. children: [
  26. const Center(
  27. child: Text(
  28. "Weekly Challenge",
  29. textAlign: TextAlign.center,
  30. style: TextStyle(
  31. fontSize: 28,
  32. fontWeight: FontWeight.bold,
  33. ),
  34. ),
  35. ),
  36. const SizedBox(height: 12),
  37. Center(
  38. child: Text(
  39. "Location: $weeklyPlaceName",
  40. textAlign: TextAlign.center,
  41. maxLines: 2,
  42. overflow: TextOverflow.ellipsis,
  43. style: const TextStyle(fontSize: 18),
  44. ),
  45. ),
  46. const SizedBox(height: 48),
  47. const ChallengeExercises(getChallenge: ChallengeService.getWeeklyChallenge),
  48. const SizedBox(height: 48),
  49. NavigationButton(weeklyPlaceLocation: weeklyPlaceLocation),
  50. ],
  51. ),
  52. ),
  53. );
  54. });
  55. }
  56. }
  57. class NavigationButton extends StatelessWidget {
  58. const NavigationButton({
  59. Key? key,
  60. required this.weeklyPlaceLocation,
  61. }) : super(key: key);
  62. final dynamic weeklyPlaceLocation;
  63. @override
  64. Widget build(BuildContext context) {
  65. return ElevatedButton(
  66. style: ElevatedButton.styleFrom(primary: Colors.teal),
  67. onPressed: () => Navigator.push(
  68. context,
  69. MaterialPageRoute(
  70. builder: (_) => NavigationPage(destination: weeklyPlaceLocation),
  71. ),
  72. ),
  73. child: Padding(
  74. padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
  75. child: Row(
  76. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  77. children: const [
  78. Flexible(child: Text("Show me the way", style: TextStyle(fontSize: 24), maxLines: 2)),
  79. Icon(Icons.map, size: 32),
  80. ],
  81. ),
  82. ),
  83. );
  84. }
  85. }