Skip to content

Commit

Permalink
feat: add water (hydration), distance, and calories
Browse files Browse the repository at this point in the history
  • Loading branch information
Turtlepaw committed Oct 30, 2024
1 parent 6efcf05 commit c5f5a79
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 186 deletions.
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<uses-permission android:name="android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND" />
<uses-permission android:name="android.permission.health.READ_STEPS"/>
<uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
<uses-permission android:name="android.permission.health.READ_DISTANCE"/>
<uses-permission android:name="android.permission.health.READ_HYDRATION"/>
<uses-permission android:name="android.permission.health.READ_TOTAL_CALORIES_BURNED"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.INTERNET" />

Expand Down
8 changes: 4 additions & 4 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const String apiUrl = "https://fitnesschallenges.webredirect.org";
const types = [
HealthDataType.STEPS,
HealthDataType.HEART_RATE,
HealthDataType.DISTANCE_DELTA,
HealthDataType.WATER,
HealthDataType.TOTAL_CALORIES_BURNED,
];

const permissions = [
HealthDataAccess.READ,
HealthDataAccess.READ,
];
var permissions = types.map((type) => HealthDataAccess.READ).toList();

final pbDateFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
40 changes: 35 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void callbackDispatcher() {
final pb = await initializePocketbase();
if (!pb.authStore.isValid) return Future.value(false);
final type = await HealthTypeManager().getHealthType();
if(type == null) {
if (type == null) {
logger.debug("Health type not set, canceling work");
return Future.value(false);
}
Expand Down Expand Up @@ -318,7 +318,7 @@ void main() async {
manager.init();
healthManager.checkConnectionState();
Future.delayed(const Duration(seconds: 1), () {
healthManager.fetchHealthData();
healthManager.fetchHealthData();
});
Health().configure(useHealthConnectIfAvailable: true);
final wearManager = WearManager(pb).sendAuthentication(logger);
Expand Down Expand Up @@ -554,6 +554,7 @@ class _HomePageState extends State<HomePage> {
final challengeProvider =
Provider.of<ChallengeProvider>(context, listen: true);
final mediaQuery = MediaQuery.of(context);
final theme = Theme.of(context);
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
Expand Down Expand Up @@ -592,13 +593,42 @@ class _HomePageState extends State<HomePage> {
);
})
else
const Center(
Center(
child: Container(
padding:
const EdgeInsets.symmetric(vertical: 25, horizontal: 30),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: theme.colorScheme.surfaceContainerHigh,
width: 1.1,
style: BorderStyle.solid,
strokeAlign: BorderSide.strokeAlignCenter,
)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [Text("No challenges...")],
children: [
Icon(
Symbols.travel_explore_rounded,
size: 50,
color: theme.colorScheme.primary,
),
const SizedBox(height: 15),
Text("You aren't in any challenges yet.",
style: theme.textTheme.titleLarge),
Text("Create or join a challenge to get started.",
style: theme.textTheme.bodyLarge),
const SizedBox(height: 5),
FilledButton.tonalIcon(
onPressed: () => _showBottomSheet(context),
icon: const Icon(Symbols.stylus_note_rounded),
label: const Text("Create or join"),
)
],
),
),
)),
const SizedBox(height: 25)
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/challenge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ class _ChallengeDialogState extends State<ChallengeDialog> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"${formatNumber(data['totalValue'] as int)} steps",
"${formatInt(data['totalValue'] as int)} steps",
style: theme.textTheme.titleLarge?.copyWith(
color: theme.colorScheme.onPrimary),
),
Expand Down
42 changes: 41 additions & 1 deletion lib/routes/challenges/bingo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import 'dart:math';

import 'package:confetti/confetti.dart'; // Import the confetti package
import 'package:dynamic_color/dynamic_color.dart';
import 'package:fitness_challenges/utils/health.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_avatar/flutter_advanced_avatar.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:pocketbase/pocketbase.dart';
import 'package:provider/provider.dart';

import '../../utils/bingo/data.dart';
import '../../utils/common.dart';

class BingoCardWidget extends StatefulWidget {
final Widget Function(BuildContext) buildTopDetails;
Expand Down Expand Up @@ -111,6 +113,7 @@ class _BingoCardWidgetState extends State<BingoCardWidget> {
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
final health = Provider.of<HealthManager>(context);

return LayoutBuilder(
builder: (context, constraints) {
Expand Down Expand Up @@ -233,7 +236,7 @@ class _BingoCardWidgetState extends State<BingoCardWidget> {
),
const SizedBox(height: 10),
Text(
activity.amount.toString(),
formatNumber(activity.amount),
textAlign: TextAlign.center,
style: theme.textTheme.labelLarge?.copyWith(
color: theme.colorScheme.onPrimary,
Expand Down Expand Up @@ -270,6 +273,25 @@ class _BingoCardWidgetState extends State<BingoCardWidget> {
),
),

Padding(
padding: const EdgeInsets.only(left: 8),
child: GridView(
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5,
crossAxisSpacing: 5.0,
mainAxisSpacing: 5.0,
),
shrinkWrap: true,
children: [
_buildDataBlock(
health.steps
),

],
),
),

// Horizontal scroll of other users' bingo cards
_buildOtherUsersCards(manager),

Expand All @@ -281,6 +303,24 @@ class _BingoCardWidgetState extends State<BingoCardWidget> {
);
}

Widget _buildDataBlock(int? value){
var theme = Theme.of(context);

return Row(
children: [
const Icon(
Symbols.steps_rounded,
size: 15,
),
const SizedBox(width: 8),
Text(
formatNumber(value ?? 0),
style: theme.textTheme.bodyLarge,
)
],
);
}

Widget _buildOtherUsersCards(BingoDataManager manager) {
var theme = Theme.of(context);

Expand Down
6 changes: 3 additions & 3 deletions lib/routes/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class _CreateDialogState extends State<CreateDialog> {
ReactiveFormConsumer(builder: (context, form, widget) =>
_isCreating
? const Padding(
padding: EdgeInsets.symmetric(horizontal: 15),
padding: EdgeInsets.only(right: 25),
child: SizedBox(
width: 15,
height: 15,
child: CircularProgressIndicator(
strokeCap: StrokeCap.round),
strokeCap: StrokeCap.round, strokeWidth: 3.2,),
)
)
: TextButton(
Expand Down Expand Up @@ -287,7 +287,7 @@ class CreateWidget extends StatelessWidget {
.control(type)
.value == index,
);
}).toList(),
}),
],
),
// const SizedBox(
Expand Down
Loading

0 comments on commit c5f5a79

Please sign in to comment.