home_page.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import 'package:flutter/material.dart';
  2. import 'package:physigo/Services/AuthService.dart';
  3. import 'package:physigo/challenge/daily_challenge_page.dart';
  4. import 'package:physigo/challenge/weekly_challenge_page.dart';
  5. import '../challenges/challenges_utils.dart';
  6. class HomePage extends StatelessWidget {
  7. const HomePage({Key? key}) : super(key: key);
  8. String get name => AuthenticationServices.user!.name;
  9. num get totalPoint => AuthenticationServices.user!.totalPoints;
  10. @override
  11. Widget build(BuildContext context) {
  12. ChallengesUtils.generateChallengeIfNeeded();
  13. return Padding(
  14. padding: const EdgeInsets.all(16.0),
  15. child: Column(
  16. mainAxisAlignment: MainAxisAlignment.center,
  17. children: [
  18. Text(
  19. "Welcome back $name!",
  20. textAlign: TextAlign.center,
  21. style: const TextStyle(
  22. fontSize: 28,
  23. fontWeight: FontWeight.bold,
  24. ),
  25. ),
  26. const SizedBox(height: 36),
  27. Column(
  28. children: const [
  29. Align(
  30. alignment: Alignment.bottomLeft,
  31. child: Text(
  32. "Here are your challenges:",
  33. style: TextStyle(fontSize: 24),
  34. ),
  35. ),
  36. SizedBox(height: 24),
  37. ChallengeTile(
  38. challengeType: "Daily",
  39. challengePage: DailyChallengePage(),
  40. ),
  41. ChallengeTile(
  42. challengeType: "Weekly",
  43. challengePage: WeeklyChallengePage(),
  44. ),
  45. ],
  46. ),
  47. ],
  48. ),
  49. );
  50. }
  51. }
  52. class ChallengeTile extends StatelessWidget {
  53. final Widget challengePage;
  54. const ChallengeTile({
  55. required this.challengePage,
  56. required this.challengeType,
  57. Key? key,
  58. }) : super(key: key);
  59. final String challengeType;
  60. @override
  61. Widget build(BuildContext context) {
  62. return SizedBox(
  63. width: MediaQuery.of(context).size.width * 0.6,
  64. child: Card(
  65. elevation: 3,
  66. color: Colors.blueGrey,
  67. child: ListTile(
  68. title: Text(
  69. challengeType.toUpperCase(),
  70. textAlign: TextAlign.center,
  71. style: const TextStyle(
  72. fontSize: 18,
  73. fontWeight: FontWeight.bold,
  74. letterSpacing: 1.8,
  75. color: Colors.white,
  76. ),
  77. ),
  78. trailing: const Icon(Icons.arrow_forward, color: Colors.white),
  79. onTap: () {
  80. Navigator.push(context, MaterialPageRoute(builder: (_) => challengePage));
  81. },
  82. ),
  83. ),
  84. );
  85. }
  86. }