Skip to content

Commit

Permalink
Added confetti rain for high score event (#286)
Browse files Browse the repository at this point in the history
* Added confetti rain for high score event

* Remove asset

* Bump v0.7.5+34

* Linting
  • Loading branch information
andreped authored Sep 22, 2024
1 parent 59a9b3e commit 3ef068d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 44 deletions.
117 changes: 74 additions & 43 deletions lib/tabs/inputs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../core/database.dart';
import '../core/convert.dart';
import 'package:confetti/confetti.dart';

class ExerciseSetter extends StatefulWidget {
final Function() onExerciseAdded;
Expand All @@ -18,6 +19,7 @@ class _ExerciseSetterState extends State<ExerciseSetter> {
final _weightController = TextEditingController();
final _repsController = TextEditingController();
final _setsController = TextEditingController(text: '1'); // Default sets to 1
late ConfettiController _confettiController;

// Controllers for "Fitness" logging
final _userWeightController = TextEditingController();
Expand All @@ -42,6 +44,14 @@ class _ExerciseSetterState extends State<ExerciseSetter> {
void initState() {
super.initState();
_loadPredefinedExercises();
_confettiController =
ConfettiController(duration: const Duration(seconds: 4));
}

@override
void dispose() {
_confettiController.dispose();
super.dispose();
}

Future<void> _loadPredefinedExercises() async {
Expand Down Expand Up @@ -161,6 +171,9 @@ class _ExerciseSetterState extends State<ExerciseSetter> {
duration: Duration(seconds: 2),
backgroundColor: Colors.green,
));

// Start confetti
_confettiController.play();
} else {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('🎯 Exercise added successfully'),
Expand Down Expand Up @@ -363,53 +376,71 @@ class _ExerciseSetterState extends State<ExerciseSetter> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Log Exercise'),
actions: [
// Dropdown to select "Exercise" or "Fitness" logging
DropdownButton<String>(
value: _selectedLoggingType,
onChanged: (String? newValue) async {
setState(() {
_selectedLoggingType = newValue!;
});

// Load the last logged data for the selected type
await _loadLastLoggedExercise();
},
items: <String>['Exercise', 'Fitness']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
return Stack(
children: [
Scaffold(
appBar: AppBar(
title: const Text('Log Exercise'),
actions: [
// Dropdown to select "Exercise" or "Fitness" logging
DropdownButton<String>(
value: _selectedLoggingType,
onChanged: (String? newValue) async {
setState(() {
_selectedLoggingType = newValue!;
});

// Load the last logged data for the selected type
await _loadLastLoggedExercise();
},
items: <String>['Exercise', 'Fitness']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
],
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_selectedLoggingType == 'Exercise') ...[
_buildExerciseForm(),
] else if (_selectedLoggingType == 'Fitness') ...[
_buildFitnessForm(),
],
SizedBox(height: 20),
if (!_isAddingNewExercise)
ElevatedButton(
onPressed: _addOrUpdateExercise,
child: Text('Save'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (_selectedLoggingType == 'Exercise') ...[
_buildExerciseForm(),
] else if (_selectedLoggingType == 'Fitness') ...[
_buildFitnessForm(),
],
SizedBox(height: 20),
if (!_isAddingNewExercise)
ElevatedButton(
onPressed: _addOrUpdateExercise,
child: Text('Save'),
),
],
),
),
),
),
Align(
alignment: Alignment.topCenter,
child: ConfettiWidget(
confettiController: _confettiController,
blastDirectionality: BlastDirectionality.explosive,
shouldLoop: false,
colors: const [
Colors.red,
Colors.blue,
Colors.green,
Colors.yellow
],
),
),
),
],
);
}

Expand Down
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.7.4+33
version: 0.7.5+34

environment:
sdk: '>=3.4.3 <4.0.0'
Expand All @@ -43,6 +43,9 @@ dependencies:
path_provider: ^2.0.11
file_picker: ^5.3.1

# high score stuff
confetti: ^0.6.0

# permissions android
permission_handler: ^10.2.0

Expand Down

0 comments on commit 3ef068d

Please sign in to comment.