challenge_page.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import 'package:cloud_firestore/cloud_firestore.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:physigo/challenges/challenges_utils.dart';
  4. import 'package:physigo/challenges/challenge.dart';
  5. class ChallengePage extends StatelessWidget {
  6. const ChallengePage({Key? key}) : super(key: key);
  7. @override
  8. Widget build(BuildContext context) {
  9. return Scaffold(
  10. body: FutureBuilder<DocumentSnapshot<Map<String, dynamic>>>(
  11. future: ChallengesUtils.getChallenge(),
  12. builder: (context, snapshot) {
  13. switch (snapshot.connectionState) {
  14. case ConnectionState.waiting:
  15. return const Center(
  16. child: Text('Getting challenges...'),
  17. );
  18. case ConnectionState.done:
  19. if (snapshot.hasError) {
  20. return const Text('Error occurred');
  21. }
  22. if (snapshot.hasData) {
  23. return buildChallenge(snapshot.data!, context);
  24. }
  25. return const Text('No data');
  26. default:
  27. return const Text('Dunno');
  28. }
  29. },
  30. ),
  31. );
  32. }
  33. }