User can now customize bar and plate weights

This commit is contained in:
Ayush Sourav Jagaty
2024-11-27 21:13:27 +05:30
parent a3858cd2f7
commit b919e622ec
11 changed files with 260 additions and 22 deletions

View File

@@ -121,4 +121,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048
COCOAPODS: 1.16.0
COCOAPODS: 1.15.2

View File

@@ -74,7 +74,7 @@ const DEFAULT_ANIMATION_CURVE = Curves.bounceIn;
final DateFormatLists = DateFormat('yyyy-MM-dd');
/// Available plate weights, used for the plate calculator
const AVAILABLE_PLATES = [1.25, 2.5, 5, 10, 15];
const AVAILABLE_PLATES = [1.25, 2.5, 5, 10, 15,20,25];
/// Weight of the bar, used in the plate calculator
const BAR_WEIGHT = 20;

View File

@@ -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();
}
}

View File

@@ -19,7 +19,7 @@
/// Calculates the number of plates needed to reach a specific weight
List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
final List<num> ans = [];
print("total weight is $totalWeight");
// Weight is less than the bar
if (totalWeight < barWeight) {
return [];

View File

@@ -15,7 +15,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
@@ -27,6 +26,7 @@ import 'package:wger/providers/exercises.dart';
import 'package:wger/providers/gallery.dart';
import 'package:wger/providers/measurement.dart';
import 'package:wger/providers/nutrition.dart';
import 'package:wger/providers/plate_weights.dart';
import 'package:wger/providers/user.dart';
import 'package:wger/providers/workout_plans.dart';
import 'package:wger/screens/add_exercise_screen.dart';
@@ -57,7 +57,7 @@ import 'providers/auth.dart';
void main() async {
//zx.setLogEnabled(kDebugMode);
// Needs to be called before runApp
WidgetsFlutterBinding.ensureInitialized();
@@ -73,6 +73,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => PlateWeights()),
ChangeNotifierProvider(create: (ctx) => AuthProvider()),
ChangeNotifierProxyProvider<AuthProvider, ExercisesProvider>(
create: (context) => ExercisesProvider(

View File

@@ -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();
}
}

View File

@@ -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))
)
]),
),
));
}
}

View File

@@ -37,7 +37,9 @@ import 'package:wger/models/workouts/set.dart';
import 'package:wger/models/workouts/setting.dart';
import 'package:wger/models/workouts/workout_plan.dart';
import 'package:wger/providers/exercises.dart';
import 'package:wger/providers/plate_weights.dart';
import 'package:wger/providers/workout_plans.dart';
import 'package:wger/screens/add_plate_weights.dart';
import 'package:wger/theme/theme.dart';
import 'package:wger/widgets/core/core.dart';
import 'package:wger/widgets/exercises/images.dart';
@@ -546,29 +548,53 @@ class _LogPageState extends State<LogPage> {
}
Widget getPlates() {
num x=num.parse(_weightController.text);
final plates = plateCalculator(
double.parse(_weightController.text),
x,
BAR_WEIGHT,
AVAILABLE_PLATES,
);
final groupedPlates = groupPlates(plates);
Map<num,int> groupedPlates;
groupedPlates = groupPlates(plates);
return Consumer<PlateWeights>(
builder: (context,plate_provider,child)=>
Column(
children: [
Container(
child: Text("Weight of Bar is :- $BAR_WEIGHT Kg's",style: TextStyle(fontSize: 20),),
),
SizedBox(height: 10,),
Container(
child: Text("Available Weight's are:- ",style: TextStyle(fontSize: 20),),
),
SizedBox(height: 10,),
Container(
child: Text("kg: 1.25, 2.5, 5, 10, 15, 20, and 25 kg",style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold)),
),
Container(
child: Text("lb: 2.5, 5, 10, 25, 35, and 45 lbs",style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),),
),
return Column(
children: [
Text(
AppLocalizations.of(context).plateCalculator,
style: Theme.of(context).textTheme.titleLarge,
),
SizedBox(
height: 35,
child: plates.isNotEmpty
ElevatedButton(onPressed: (){
plate_provider.weight_in_kg=x;
plate_provider.tot_weight=x;
plate_provider.printweights();
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>const AddPlateWeights()));
},
child: Text("Enter custom Denomination's")
),
SizedBox(
height: 35,
child: (plate_provider.flag?plate_provider.weights.isNotEmpty:plates.isNotEmpty)
? Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
...groupedPlates.keys.map(
...(plate_provider.flag?plate_provider.grouped:groupedPlates).keys.map(
(key) => Row(
children: [
Text(groupedPlates[key].toString()),
Text(plate_provider.flag?(plate_provider.grouped[key].toString()):(groupedPlates[key].toString())),
const Text('×'),
Container(
decoration: BoxDecoration(
@@ -601,12 +627,13 @@ class _LogPageState extends State<LogPage> {
: MutedText(
AppLocalizations.of(context).plateCalculatorNotDivisible,
),
),
const SizedBox(height: 3),
],
),
],
),
);
}
@override
Widget build(BuildContext context) {
return Column(

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 73 KiB