weekly_challenge_page.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. appBar: AppBar(
  22. iconTheme: const IconThemeData(color: Colors.white, size: 36),
  23. ),
  24. body: Padding(
  25. padding: const EdgeInsets.all(16.0),
  26. child: Column(
  27. mainAxisAlignment: MainAxisAlignment.center,
  28. children: [
  29. const Center(
  30. child: Text(
  31. "Weekly Challenge",
  32. textAlign: TextAlign.center,
  33. style: TextStyle(
  34. fontSize: 28,
  35. fontWeight: FontWeight.bold,
  36. ),
  37. ),
  38. ),
  39. const SizedBox(height: 12),
  40. Center(
  41. child: Text(
  42. "Location: $weeklyPlaceName",
  43. textAlign: TextAlign.center,
  44. maxLines: 2,
  45. overflow: TextOverflow.ellipsis,
  46. style: const TextStyle(fontSize: 18),
  47. ),
  48. ),
  49. const SizedBox(height: 48),
  50. const ChallengeExercises(getChallenge: ChallengeService.getWeeklyChallenge),
  51. const SizedBox(height: 48),
  52. NavigationButton(weeklyPlaceLocation: weeklyPlaceLocation),
  53. ],
  54. ),
  55. ),
  56. );
  57. });
  58. }
  59. }
  60. class NavigationButton extends StatelessWidget {
  61. const NavigationButton({
  62. Key? key,
  63. required this.weeklyPlaceLocation,
  64. }) : super(key: key);
  65. final dynamic weeklyPlaceLocation;
  66. @override
  67. Widget build(BuildContext context) {
  68. return ElevatedButton(
  69. style: ElevatedButton.styleFrom(primary: Colors.teal),
  70. onPressed: () => Navigator.push(
  71. context,
  72. MaterialPageRoute(
  73. builder: (_) => NavigationPage(destination: weeklyPlaceLocation),
  74. ),
  75. ),
  76. child: Padding(
  77. padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
  78. child: Row(
  79. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  80. children: const [
  81. Flexible(child: Text("Show me the way", style: TextStyle(fontSize: 24), maxLines: 2)),
  82. Icon(Icons.map, size: 32),
  83. ],
  84. ),
  85. ),
  86. );
  87. }
  88. }