diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 36cfa724..f7553e9d 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -121,4 +121,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048 -COCOAPODS: 1.16.0 +COCOAPODS: 1.15.2 diff --git a/lib/helpers/consts.dart b/lib/helpers/consts.dart index 562c4a33..eccfd06f 100644 --- a/lib/helpers/consts.dart +++ b/lib/helpers/consts.dart @@ -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; diff --git a/lib/helpers/exercises/plate_configurator.dart b/lib/helpers/exercises/plate_configurator.dart new file mode 100644 index 00000000..37770bef --- /dev/null +++ b/lib/helpers/exercises/plate_configurator.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class PlateConfiguration extends ChangeNotifier { + //olympic standard weights + List _plateWeights = [1.25, 2.5, 5, 10, 15, 20, 25]; + + List get plateWeights => _plateWeights; + + void setPlateWeights(List weights) { + _plateWeights = weights; + notifyListeners(); + } +} \ No newline at end of file diff --git a/lib/helpers/gym_mode.dart b/lib/helpers/gym_mode.dart index ffad3e26..6f634c2b 100644 --- a/lib/helpers/gym_mode.dart +++ b/lib/helpers/gym_mode.dart @@ -19,7 +19,7 @@ /// Calculates the number of plates needed to reach a specific weight List plateCalculator(num totalWeight, num barWeight, List plates) { final List ans = []; - + print("total weight is $totalWeight"); // Weight is less than the bar if (totalWeight < barWeight) { return []; diff --git a/lib/main.dart b/lib/main.dart index ac4abfe1..118cf95c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,7 +15,6 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - 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( create: (context) => ExercisesProvider( diff --git a/lib/providers/plate_weights.dart b/lib/providers/plate_weights.dart new file mode 100644 index 00000000..e8b8391e --- /dev/null +++ b/lib/providers/plate_weights.dart @@ -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 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 weights =[0]; + List custom_plates = []; + late Map 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 createState() => _AddPlateWeightsState(); +} + +class _AddPlateWeightsState extends State { + @override + Widget build(BuildContext context) { + return Consumer( + 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( + 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 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)) + ) + ]), + ), + )); + + } +} + diff --git a/lib/widgets/workouts/gym_mode.dart b/lib/widgets/workouts/gym_mode.dart index 27a87873..899a450d 100644 --- a/lib/widgets/workouts/gym_mode.dart +++ b/lib/widgets/workouts/gym_mode.dart @@ -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 { } 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 groupedPlates; + groupedPlates = groupPlates(plates); + return Consumer( + 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 { : MutedText( AppLocalizations.of(context).plateCalculatorNotDivisible, ), - ), - const SizedBox(height: 3), - ], + ), + ], + + ), + ); } - @override Widget build(BuildContext context) { return Column( diff --git a/test/nutrition/goldens/nutritional_plan_1_default_view.png b/test/nutrition/goldens/nutritional_plan_1_default_view.png index 09745b0c..79ec2fc9 100644 Binary files a/test/nutrition/goldens/nutritional_plan_1_default_view.png and b/test/nutrition/goldens/nutritional_plan_1_default_view.png differ diff --git a/test/nutrition/goldens/nutritional_plan_2_one_meal_with_ingredients.png b/test/nutrition/goldens/nutritional_plan_2_one_meal_with_ingredients.png index 09a8c964..a44af8b9 100644 Binary files a/test/nutrition/goldens/nutritional_plan_2_one_meal_with_ingredients.png and b/test/nutrition/goldens/nutritional_plan_2_one_meal_with_ingredients.png differ diff --git a/test/nutrition/goldens/nutritional_plan_3_both_meals_with_ingredients.png b/test/nutrition/goldens/nutritional_plan_3_both_meals_with_ingredients.png index 9ef95623..3d24404c 100644 Binary files a/test/nutrition/goldens/nutritional_plan_3_both_meals_with_ingredients.png and b/test/nutrition/goldens/nutritional_plan_3_both_meals_with_ingredients.png differ