-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User can now customize bar and plate weights
- Loading branch information
Ayush Sourav Jagaty
authored and
Ayush Sourav Jagaty
committed
Nov 27, 2024
1 parent
a3858cd
commit b919e62
Showing
11 changed files
with
260 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class PlateConfiguration extends ChangeNotifier { | ||
//olympic standard weights | ||
List<double> _plateWeights = [1.25, 2.5, 5, 10, 15, 20, 25]; | ||
|
||
List<double> get plateWeights => _plateWeights; | ||
|
||
void setPlateWeights(List<double> weights) { | ||
_plateWeights = weights; | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:wger/helpers/consts.dart'; | ||
import 'package:wger/helpers/gym_mode.dart'; | ||
|
||
class PlateWeights extends ChangeNotifier{ | ||
List<TextEditingController> plate_weights = [TextEditingController()]; | ||
TextEditingController bar_weight_controller = TextEditingController(); | ||
String unit_of_plate='kg'; | ||
bool flag=false; | ||
int num_inputs=1; | ||
num tot_weight=0; | ||
num c_bar=0; | ||
num convert_to_lbs=2.205; | ||
num weight_in_kg = 0; | ||
num bar_weight_in_kg = 0; | ||
List<num> weights =[0]; | ||
List<num> custom_plates = []; | ||
late Map<num,int> grouped ; | ||
void unit_change(){ | ||
flag=!flag; | ||
if(flag){ | ||
tot_weight = weight_in_kg; | ||
unit_of_plate='kg'; | ||
c_bar=bar_weight_in_kg; | ||
} | ||
else{ | ||
unit_of_plate='lbs'; | ||
tot_weight = weight_in_kg*2.205; | ||
c_bar = bar_weight_in_kg*2.205; | ||
} | ||
notifyListeners(); | ||
} | ||
void addrow(){ | ||
weights.add(0); | ||
num_inputs++; | ||
plate_weights.add(TextEditingController()); | ||
notifyListeners(); | ||
} | ||
void remove(){ | ||
if(num_inputs>1){ | ||
num_inputs--; | ||
plate_weights.removeLast; | ||
notifyListeners(); | ||
} | ||
} | ||
void clear(){ | ||
weights.clear(); | ||
notifyListeners(); | ||
} | ||
void calc(){ | ||
weights.sort(); | ||
custom_plates = plateCalculator(tot_weight,c_bar,weights); | ||
grouped = groupPlates(custom_plates); | ||
for(int i=0;i<custom_plates.length;++i){ | ||
num y = custom_plates[i]; | ||
print("object"); | ||
print(" | | $y"); | ||
} | ||
notifyListeners(); | ||
} | ||
void printweights(){ | ||
//print("--------------!!!!_____"); | ||
for(int i=0;i<weights.length;++i){ | ||
num y = weights[i]; | ||
print("$i is $y"); | ||
notifyListeners(); | ||
} | ||
} | ||
void reset(){ | ||
weights=[]; | ||
bar_weight_controller.clear(); | ||
bar_weight_controller=TextEditingController(); | ||
plate_weights.clear(); | ||
plate_weights = [TextEditingController()]; | ||
num_inputs=1; | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:wger/providers/plate_weights.dart'; | ||
|
||
class AddPlateWeights extends StatefulWidget { | ||
const AddPlateWeights({super.key}); | ||
|
||
@override | ||
State<AddPlateWeights> createState() => _AddPlateWeightsState(); | ||
} | ||
|
||
class _AddPlateWeightsState extends State<AddPlateWeights> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Consumer<PlateWeights>( | ||
builder:(context,plate_provider,child)=> Scaffold( | ||
appBar: AppBar( | ||
title: Text('Enter Details'), | ||
), | ||
body: SingleChildScrollView( | ||
child: Column( | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Text('Kg or lbs'), | ||
DropdownButton( | ||
onChanged: (newValue){ | ||
plate_provider.unit_change(); | ||
plate_provider.unit_of_plate=newValue!; | ||
}, items: ["kg","lbs"].map((unit){ | ||
return DropdownMenuItem<String>( | ||
value: unit, | ||
child: Text(unit), | ||
); | ||
}).toList(), | ||
), | ||
], | ||
|
||
), | ||
//Text('Enter Bar Weight:-',style: TextStyle(fontSize: 20),), | ||
|
||
TextField( | ||
controller: plate_provider.bar_weight_controller, | ||
keyboardType: TextInputType.number, | ||
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,3}')),], | ||
decoration: const InputDecoration( | ||
hintText: "Enter Bar Weight", | ||
), | ||
onChanged: (value){ | ||
plate_provider.bar_weight_in_kg=num.parse(value); | ||
plate_provider.c_bar=num.parse(value); | ||
}, | ||
), | ||
Text(plate_provider.unit_of_plate,style: TextStyle(fontSize: 20),), | ||
for (int i = 0; i <plate_provider.num_inputs; i++) | ||
Row( | ||
children: [ | ||
Expanded( | ||
child: TextField( | ||
controller: plate_provider.plate_weights[i], | ||
decoration: const InputDecoration( | ||
hintText: 'Enter Plate weight', | ||
), | ||
keyboardType: TextInputType.number, | ||
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,3}')),], | ||
onChanged: (value){ | ||
int val = int.parse(value); | ||
plate_provider.weights[i]=(num.parse(value)); | ||
// while(val>0){ | ||
// print("val is $val"); | ||
// plate_provider.weights.remove(val/10); | ||
// val~/=10; | ||
// } | ||
}, | ||
), | ||
), | ||
IconButton( | ||
icon: Icon(Icons.delete), | ||
onPressed: () { | ||
plate_provider.remove(); | ||
}, | ||
), | ||
], | ||
), | ||
ElevatedButton( | ||
onPressed:(){ | ||
plate_provider.addrow(); | ||
}, | ||
child: Text('Add Weight'), | ||
), | ||
TextButton( | ||
onPressed: (){ | ||
if(plate_provider.weights.length>=1){ | ||
plate_provider.flag=true; | ||
plate_provider.calc();} | ||
print("object"); | ||
print(plate_provider.weights.length); | ||
Navigator.pop(context); | ||
}, | ||
child: Text('Done'), | ||
), | ||
ElevatedButton( | ||
onPressed: (){ | ||
plate_provider.reset(); | ||
}, | ||
child: Text("Reset",style: TextStyle(color: Colors.red,fontWeight: FontWeight.bold)) | ||
) | ||
]), | ||
), | ||
)); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.5 KB
(110%)
test/nutrition/goldens/nutritional_plan_2_one_meal_with_ingredients.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.25 KB
(100%)
test/nutrition/goldens/nutritional_plan_3_both_meals_with_ingredients.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.