mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Some refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Uncomment this line to define a global platform for your project
|
# Uncomment this line to define a global platform for your project
|
||||||
platform :ios, '14.0'
|
platform :ios, '17.0'
|
||||||
|
|
||||||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
||||||
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
||||||
|
|||||||
@@ -22,23 +22,23 @@ PODS:
|
|||||||
- shared_preferences_foundation (0.0.1):
|
- shared_preferences_foundation (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
- sqlite3 (3.49.1):
|
- sqlite3 (3.49.2):
|
||||||
- sqlite3/common (= 3.49.1)
|
- sqlite3/common (= 3.49.2)
|
||||||
- sqlite3/common (3.49.1)
|
- sqlite3/common (3.49.2)
|
||||||
- sqlite3/dbstatvtab (3.49.1):
|
- sqlite3/dbstatvtab (3.49.2):
|
||||||
- sqlite3/common
|
- sqlite3/common
|
||||||
- sqlite3/fts5 (3.49.1):
|
- sqlite3/fts5 (3.49.2):
|
||||||
- sqlite3/common
|
- sqlite3/common
|
||||||
- sqlite3/math (3.49.1):
|
- sqlite3/math (3.49.2):
|
||||||
- sqlite3/common
|
- sqlite3/common
|
||||||
- sqlite3/perf-threadsafe (3.49.1):
|
- sqlite3/perf-threadsafe (3.49.2):
|
||||||
- sqlite3/common
|
- sqlite3/common
|
||||||
- sqlite3/rtree (3.49.1):
|
- sqlite3/rtree (3.49.2):
|
||||||
- sqlite3/common
|
- sqlite3/common
|
||||||
- sqlite3_flutter_libs (0.0.1):
|
- sqlite3_flutter_libs (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
- sqlite3 (~> 3.49.1)
|
- sqlite3 (~> 3.49.2)
|
||||||
- sqlite3/dbstatvtab
|
- sqlite3/dbstatvtab
|
||||||
- sqlite3/fts5
|
- sqlite3/fts5
|
||||||
- sqlite3/math
|
- sqlite3/math
|
||||||
@@ -101,10 +101,10 @@ EXTERNAL SOURCES:
|
|||||||
:path: ".symlinks/plugins/video_player_avfoundation/darwin"
|
:path: ".symlinks/plugins/video_player_avfoundation/darwin"
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
camera_avfoundation: 04b44aeb14070126c6529e5ab82cc7c9fca107cf
|
camera_avfoundation: be3be85408cd4126f250386828e9b1dfa40ab436
|
||||||
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
||||||
flutter_keyboard_visibility: 4625131e43015dbbe759d9b20daaf77e0e3f6619
|
flutter_keyboard_visibility: 4625131e43015dbbe759d9b20daaf77e0e3f6619
|
||||||
flutter_zxing: e741c4f3335db8910e5c396c4291cdfb320859dc
|
flutter_zxing: e8bcc43bd3056c70c271b732ed94e7a16fd62f93
|
||||||
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a
|
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a
|
||||||
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e
|
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e
|
||||||
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
|
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
|
||||||
@@ -112,11 +112,11 @@ SPEC CHECKSUMS:
|
|||||||
pointer_interceptor_ios: ec847ef8b0915778bed2b2cef636f4d177fa8eed
|
pointer_interceptor_ios: ec847ef8b0915778bed2b2cef636f4d177fa8eed
|
||||||
rive_common: dd421daaf9ae69f0125aa761dd96abd278399952
|
rive_common: dd421daaf9ae69f0125aa761dd96abd278399952
|
||||||
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
|
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
|
||||||
sqlite3: fc1400008a9b3525f5914ed715a5d1af0b8f4983
|
sqlite3: 3c950dc86011117c307eb0b28c4a7bb449dce9f1
|
||||||
sqlite3_flutter_libs: f6acaa2172e6bb3e2e70c771661905080e8ebcf2
|
sqlite3_flutter_libs: 74334e3ef2dbdb7d37e50859bb45da43935779c4
|
||||||
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
|
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
|
||||||
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b
|
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b
|
||||||
|
|
||||||
PODFILE CHECKSUM: 775997f741c536251164e3eacf6e34abf2eb7a17
|
PODFILE CHECKSUM: 5a367937f10bf0c459576e5e472a1159ee029c13
|
||||||
|
|
||||||
COCOAPODS: 1.16.2
|
COCOAPODS: 1.16.2
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class PlateConfiguration extends ChangeNotifier {
|
class PlateConfiguration extends ChangeNotifier {
|
||||||
//olympic standard weights
|
//olympic standard weights
|
||||||
List<double> _plateWeights = [1.25, 2.5, 5, 10, 15, 20, 25];
|
List<double> _plateWeights = [1.25, 2.5, 5, 10, 15, 20, 25];
|
||||||
|
|
||||||
List<double> get plateWeights => _plateWeights;
|
List<double> get plateWeights => _plateWeights;
|
||||||
|
|
||||||
@@ -10,4 +10,4 @@ class PlateConfiguration extends ChangeNotifier {
|
|||||||
_plateWeights = weights;
|
_plateWeights = weights;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,17 @@
|
|||||||
|
|
||||||
/// Calculates the number of plates needed to reach a specific weight
|
/// Calculates the number of plates needed to reach a specific weight
|
||||||
List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
||||||
final List<num> ans = [];
|
final List<num> result = [];
|
||||||
|
|
||||||
// Weight is less than the bar
|
// Weight is less than the bar
|
||||||
if (totalWeight < barWeight) {
|
if (totalWeight < barWeight) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (plates.isEmpty) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the bar and divide by two to get weight on each side
|
// Remove the bar and divide by two to get weight on each side
|
||||||
totalWeight = (totalWeight - barWeight) / 2;
|
totalWeight = (totalWeight - barWeight) / 2;
|
||||||
|
|
||||||
@@ -36,11 +41,11 @@ List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
|||||||
for (final plate in plates.reversed) {
|
for (final plate in plates.reversed) {
|
||||||
while (totalWeight >= plate) {
|
while (totalWeight >= plate) {
|
||||||
totalWeight -= plate;
|
totalWeight -= plate;
|
||||||
ans.add(plate);
|
result.add(plate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Groups a list of plates as calculated by [plateCalculator]
|
/// Groups a list of plates as calculated by [plateCalculator]
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod;
|
import 'package:flutter_riverpod/flutter_riverpod.dart' as riverpod;
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import 'package:wger/core/locator.dart';
|
import 'package:wger/core/locator.dart';
|
||||||
import 'package:wger/exceptions/http_exception.dart';
|
import 'package:wger/exceptions/http_exception.dart';
|
||||||
import 'package:wger/helpers/errors.dart';
|
import 'package:wger/helpers/errors.dart';
|
||||||
@@ -34,8 +33,8 @@ import 'package:wger/providers/exercises.dart';
|
|||||||
import 'package:wger/providers/gallery.dart';
|
import 'package:wger/providers/gallery.dart';
|
||||||
import 'package:wger/providers/measurement.dart';
|
import 'package:wger/providers/measurement.dart';
|
||||||
import 'package:wger/providers/nutrition.dart';
|
import 'package:wger/providers/nutrition.dart';
|
||||||
import 'package:wger/providers/routines.dart';
|
|
||||||
import 'package:wger/providers/plate_weights.dart';
|
import 'package:wger/providers/plate_weights.dart';
|
||||||
|
import 'package:wger/providers/routines.dart';
|
||||||
import 'package:wger/providers/user.dart';
|
import 'package:wger/providers/user.dart';
|
||||||
import 'package:wger/screens/add_exercise_screen.dart';
|
import 'package:wger/screens/add_exercise_screen.dart';
|
||||||
import 'package:wger/screens/auth_screen.dart';
|
import 'package:wger/screens/auth_screen.dart';
|
||||||
@@ -103,7 +102,8 @@ void main() async {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
showGeneralErrorDialog(details.exception, stack);
|
// showGeneralErrorDialog(details.exception, stack);
|
||||||
|
throw details.exception;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Catch errors that happen outside of the Flutter framework (e.g., in async operations)
|
// Catch errors that happen outside of the Flutter framework (e.g., in async operations)
|
||||||
@@ -115,7 +115,8 @@ void main() async {
|
|||||||
if (error is WgerHttpException) {
|
if (error is WgerHttpException) {
|
||||||
showHttpExceptionErrorDialog(error);
|
showHttpExceptionErrorDialog(error);
|
||||||
} else {
|
} else {
|
||||||
showGeneralErrorDialog(error, stack);
|
// showGeneralErrorDialog(error, stack);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true to indicate that the error has been handled.
|
// Return true to indicate that the error has been handled.
|
||||||
@@ -150,7 +151,7 @@ class MainApp extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider(create: (context)=> PlateWeights()),
|
ChangeNotifierProvider(create: (context) => PlateWeights()),
|
||||||
ChangeNotifierProvider(create: (ctx) => AuthProvider()),
|
ChangeNotifierProvider(create: (ctx) => AuthProvider()),
|
||||||
ChangeNotifierProxyProvider<AuthProvider, ExercisesProvider>(
|
ChangeNotifierProxyProvider<AuthProvider, ExercisesProvider>(
|
||||||
create: (context) => ExercisesProvider(
|
create: (context) => ExercisesProvider(
|
||||||
|
|||||||
@@ -1,105 +1,147 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:flutter/widgets.dart';
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:wger/helpers/gym_mode.dart';
|
import 'package:wger/helpers/gym_mode.dart';
|
||||||
|
|
||||||
class PlateWeights extends ChangeNotifier{
|
const DEFAULT_KG_PLATES = [2.5, 5, 10, 15, 20, 25];
|
||||||
|
|
||||||
|
const PREFS_KEY_PLATES = 'selectedPlates';
|
||||||
|
|
||||||
|
class PlateWeights extends ChangeNotifier {
|
||||||
|
final plateColorMapKg = {
|
||||||
|
25: Colors.red,
|
||||||
|
20: Colors.blue,
|
||||||
|
15: Colors.yellow,
|
||||||
|
10: Colors.green,
|
||||||
|
5: Colors.white,
|
||||||
|
2.5: Colors.red,
|
||||||
|
2: Colors.blue,
|
||||||
|
1.25: Colors.yellow,
|
||||||
|
1: Colors.green,
|
||||||
|
0.5: Colors.white,
|
||||||
|
};
|
||||||
|
final plateColorMapLb = {
|
||||||
|
55: Colors.red,
|
||||||
|
45: Colors.blue,
|
||||||
|
35: Colors.yellow,
|
||||||
|
25: Colors.green,
|
||||||
|
10: Colors.white,
|
||||||
|
5: Colors.blue,
|
||||||
|
1.25: Colors.white,
|
||||||
|
};
|
||||||
|
|
||||||
bool isMetric = true;
|
bool isMetric = true;
|
||||||
bool plateChoiceExists = false;
|
|
||||||
bool loadedFromSharedPref = false;
|
bool loadedFromSharedPref = false;
|
||||||
num totalWeight = 0;
|
num totalWeight = 0;
|
||||||
num barWeight = 20;
|
num barWeight = 20;
|
||||||
num convertTolbs = 2.205;
|
num convertToLbs = 2.205;
|
||||||
num totalWeightInKg = 0;
|
num totalWeightInKg = 0;
|
||||||
num barWeightInKg = 20;
|
num barWeightInKg = 20;
|
||||||
List<num> selectedWeights = [];
|
List<num> selectedPlates = [...DEFAULT_KG_PLATES];
|
||||||
List<num> kgWeights = [1.25, 2.5, 5, 10, 15, 20, 25];
|
List<num> kgWeights = [0.5, 1, 1.25, 2, 2.5, 5, 10, 15, 20, 25];
|
||||||
List<num> lbsWeights = [2.5, 5, 10, 25, 35, 45];
|
List<num> lbsWeights = [2.5, 5, 10, 25, 35, 45];
|
||||||
List<num> customPlates = [];
|
|
||||||
late Map<num,int> grouped;
|
List<num> get data => selectedPlates;
|
||||||
List<num> get data => selectedWeights;
|
|
||||||
set data(List<num> newData){
|
set data(List<num> newData) {
|
||||||
selectedWeights = newData;
|
selectedPlates = newData;
|
||||||
//saving data to shared preference
|
|
||||||
saveIntoSharedPrefs();
|
saveIntoSharedPrefs();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
Future<void> saveIntoSharedPrefs() async{
|
|
||||||
|
Color getColor(num plate) {
|
||||||
|
if (isMetric) {
|
||||||
|
return plateColorMapKg[plate] ?? Colors.white;
|
||||||
|
}
|
||||||
|
|
||||||
|
return plateColorMapLb[plate] ?? Colors.white;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveIntoSharedPrefs() async {
|
||||||
final pref = await SharedPreferences.getInstance();
|
final pref = await SharedPreferences.getInstance();
|
||||||
//converting List Weights to String
|
pref.setString(PREFS_KEY_PLATES, jsonEncode(selectedPlates));
|
||||||
final String selectedPlates = jsonEncode(selectedWeights);
|
|
||||||
pref.setString('selectedPlates', selectedPlates);
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void readPlates() async{
|
void readPlates() async {
|
||||||
final pref = await SharedPreferences.getInstance();
|
final pref = await SharedPreferences.getInstance();
|
||||||
final platePrefData = pref.getString('selectedPlates');
|
final platePrefData = pref.getString(PREFS_KEY_PLATES);
|
||||||
if(platePrefData != null){
|
if (platePrefData != null) {
|
||||||
try{
|
try {
|
||||||
final plateData = json.decode(platePrefData);
|
final plateData = json.decode(platePrefData);
|
||||||
if(plateData is List){
|
if (plateData is List) {
|
||||||
selectedWeights = plateData.cast<num>();
|
selectedPlates = plateData.cast<num>();
|
||||||
}else{
|
} else {
|
||||||
throw const FormatException('Not a List');
|
throw const FormatException('Not a List');
|
||||||
}
|
|
||||||
}catch(e){
|
|
||||||
selectedWeights = [];
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
selectedPlates = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print('loaded');
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> toggleSelection(num x) async{
|
Future<void> toggleSelection(num x) async {
|
||||||
if(selectedWeights.contains(x)) {
|
if (selectedPlates.contains(x)) {
|
||||||
selectedWeights.remove(x);
|
selectedPlates.remove(x);
|
||||||
}else {
|
} else {
|
||||||
selectedWeights.add(x);
|
selectedPlates.add(x);
|
||||||
}
|
}
|
||||||
final prefs = await SharedPreferences.getInstance();
|
await saveIntoSharedPrefs();
|
||||||
prefs.setString('selectedPlates',jsonEncode(selectedWeights));
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unitChange() {
|
void unitChange() {
|
||||||
if(isMetric==false) {
|
if (isMetric == false) {
|
||||||
totalWeight = totalWeightInKg;
|
totalWeight = totalWeightInKg;
|
||||||
isMetric = true;
|
isMetric = true;
|
||||||
barWeight = barWeightInKg;
|
barWeight = barWeightInKg;
|
||||||
} else {
|
} else {
|
||||||
isMetric = false;
|
isMetric = false;
|
||||||
totalWeight = totalWeightInKg*2.205;
|
totalWeight = totalWeightInKg * 2.205;
|
||||||
barWeight = barWeightInKg*2.205;
|
barWeight = barWeightInKg * 2.205;
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() async{
|
void clear() async {
|
||||||
selectedWeights.clear();
|
selectedPlates.clear();
|
||||||
final prefs = await SharedPreferences.getInstance();
|
await saveIntoSharedPrefs();
|
||||||
prefs.setString('selectedPlates',jsonEncode(selectedWeights));
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setWeight(num x) {
|
void setWeight(num x) {
|
||||||
totalWeight = x;
|
totalWeight = x;
|
||||||
totalWeightInKg=x;
|
totalWeightInKg = x;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculatePlates() {
|
List<num> get platesList {
|
||||||
selectedWeights.sort();
|
return plateCalculator(totalWeight, barWeight, selectedPlates);
|
||||||
customPlates = plateCalculator(totalWeight,barWeight,selectedWeights);
|
|
||||||
grouped = groupPlates(customPlates);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetPlates() async{
|
bool get hasPlates {
|
||||||
selectedWeights = [];
|
return platesList.isNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<num, int> get calculatePlates {
|
||||||
|
selectedPlates.sort();
|
||||||
|
return groupPlates(platesList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetPlates() async {
|
||||||
|
selectedPlates = [...DEFAULT_KG_PLATES];
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
prefs.setString('selectedPlates',jsonEncode(selectedWeights));
|
prefs.setString('selectedPlates', jsonEncode(selectedPlates));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void selectAllPlates() async {
|
||||||
|
selectedPlates = [...kgWeights];
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
prefs.setString('selectedPlates', jsonEncode(selectedPlates));
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:wger/helpers/consts.dart';
|
import 'package:wger/helpers/consts.dart';
|
||||||
import 'package:wger/helpers/shared_preferences.dart';
|
import 'package:wger/helpers/shared_preferences.dart';
|
||||||
import 'package:path/path.dart';
|
|
||||||
import 'package:wger/models/user/profile.dart';
|
import 'package:wger/models/user/profile.dart';
|
||||||
import 'package:wger/providers/base_provider.dart';
|
import 'package:wger/providers/base_provider.dart';
|
||||||
|
|
||||||
@@ -47,10 +46,10 @@ class UserProvider with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// change the unit of plates
|
// change the unit of plates
|
||||||
void unitChange(){
|
void unitChange() {
|
||||||
if(profile?.weightUnitStr == 'kg'){
|
if (profile?.weightUnitStr == 'kg') {
|
||||||
profile?.weightUnitStr = 'lb';
|
profile?.weightUnitStr = 'lb';
|
||||||
}else{
|
} else {
|
||||||
profile?.weightUnitStr = 'kg';
|
profile?.weightUnitStr = 'kg';
|
||||||
}
|
}
|
||||||
ChangeNotifier();
|
ChangeNotifier();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
||||||
import 'package:flutter_html/flutter_html.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:wger/providers/plate_weights.dart';
|
import 'package:wger/providers/plate_weights.dart';
|
||||||
import 'package:wger/providers/user.dart';
|
import 'package:wger/providers/user.dart';
|
||||||
@@ -12,23 +10,23 @@ class AddPlateWeights extends StatefulWidget {
|
|||||||
State<AddPlateWeights> createState() => _AddPlateWeightsState();
|
State<AddPlateWeights> createState() => _AddPlateWeightsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AddPlateWeightsState extends State<AddPlateWeights> with SingleTickerProviderStateMixin{
|
class _AddPlateWeightsState extends State<AddPlateWeights> with SingleTickerProviderStateMixin {
|
||||||
late AnimationController _controller;
|
late AnimationController _controller;
|
||||||
late Animation<Offset> _animation;
|
late Animation<Offset> _animation;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_){
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
Provider.of<PlateWeights>(context,listen: false).readPlates();
|
Provider.of<PlateWeights>(context, listen: false).readPlates();
|
||||||
});
|
});
|
||||||
_controller = AnimationController(
|
_controller = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: Duration(seconds: 1),
|
duration: const Duration(seconds: 1),
|
||||||
);
|
);
|
||||||
_animation = Tween<Offset>(
|
_animation = Tween<Offset>(
|
||||||
begin: const Offset(-1.0, 0.0), // Start off-screen
|
begin: const Offset(-1.0, 0.0), // Start off-screen
|
||||||
end: const Offset(0.0, 0.0), // End at original position
|
end: Offset.zero, // End at original position
|
||||||
).animate(CurvedAnimation(
|
).animate(CurvedAnimation(
|
||||||
parent: _controller,
|
parent: _controller,
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
@@ -45,47 +43,45 @@ late AnimationController _controller;
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
bool unit = true;
|
bool isMetric = true;
|
||||||
return Consumer2<PlateWeights,UserProvider> (
|
return Consumer2<PlateWeights, UserProvider>(
|
||||||
builder:(context,plateProvider,userProvider,child)=> Scaffold (
|
builder: (context, plateProvider, userProvider, child) => Scaffold(
|
||||||
appBar: AppBar (
|
appBar: AppBar(title: const Text('Select Available Plates')),
|
||||||
title: const Text('Select Available Plates'),
|
body: Column(
|
||||||
),
|
|
||||||
body: Column (
|
|
||||||
children: [
|
children: [
|
||||||
Row (
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Text('Preferred Unit'),
|
const Text('Preferred Unit'),
|
||||||
DropdownButton (
|
DropdownButton(
|
||||||
onChanged: (newValue){
|
onChanged: (newValue) {
|
||||||
plateProvider.clear();
|
//plateProvider.clear();
|
||||||
if(newValue=='kg') {
|
if (newValue == 'kg') {
|
||||||
unit = true;
|
isMetric = true;
|
||||||
} else {
|
} else {
|
||||||
unit = false;
|
isMetric = false;
|
||||||
}
|
}
|
||||||
print(unit);
|
if (isMetric != userProvider.profile?.isMetric) {
|
||||||
if(unit != userProvider.profile?.isMetric) {
|
|
||||||
userProvider.unitChange();
|
userProvider.unitChange();
|
||||||
//plateProvider.unitChange();
|
//plateProvider.unitChange();
|
||||||
_controller.reset();
|
_controller.reset();
|
||||||
_controller.forward();
|
_controller.forward();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
items: ['kg','lbs'].map((unit){
|
items: ['kg', 'lbs'].map((unit) {
|
||||||
return DropdownMenuItem<String> (
|
return DropdownMenuItem<String>(
|
||||||
value: unit,
|
value: unit,
|
||||||
child: Text(unit),
|
child: Text(unit),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SingleChildScrollView (
|
Wrap(
|
||||||
scrollDirection: Axis.horizontal,
|
alignment: WrapAlignment.center,
|
||||||
child: Row (
|
runAlignment: WrapAlignment.center,
|
||||||
children: (userProvider.profile?.weightUnitStr == 'kg')
|
crossAxisAlignment: WrapCrossAlignment.center,
|
||||||
|
children: (userProvider.profile == null || userProvider.profile!.isMetric)
|
||||||
? plateProvider.kgWeights.map((number) {
|
? plateProvider.kgWeights.map((number) {
|
||||||
return SlideTransition(
|
return SlideTransition(
|
||||||
position: _animation,
|
position: _animation,
|
||||||
@@ -93,19 +89,24 @@ late AnimationController _controller;
|
|||||||
onTap: () => plateProvider.toggleSelection(number),
|
onTap: () => plateProvider.toggleSelection(number),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Container (
|
child: Container(
|
||||||
|
height: 50,
|
||||||
|
width: 50,
|
||||||
|
alignment: Alignment.center,
|
||||||
margin: const EdgeInsets.all(8),
|
margin: const EdgeInsets.all(8),
|
||||||
padding: const EdgeInsets.all(16),
|
decoration: BoxDecoration(
|
||||||
decoration: BoxDecoration (
|
color: plateProvider.selectedPlates.contains(number)
|
||||||
color: plateProvider.selectedWeights.contains(number)
|
? plateProvider.getColor(number)
|
||||||
? const Color.fromARGB(255, 82, 226, 236)
|
|
||||||
: const Color.fromARGB(255, 97, 105, 101),
|
: const Color.fromARGB(255, 97, 105, 101),
|
||||||
borderRadius: BorderRadius.circular(10),
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(color: Colors.black, width: 2),
|
||||||
),
|
),
|
||||||
child: Text (
|
child: Text(
|
||||||
'$number kg', // Add unit to text
|
number.toString(),
|
||||||
|
// '$number ${plateProvider.selectedPlates.contains(number) ? "\n✓" : ""}',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.black,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -124,13 +125,13 @@ late AnimationController _controller;
|
|||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.all(8),
|
margin: const EdgeInsets.all(8),
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
decoration: BoxDecoration (
|
decoration: BoxDecoration(
|
||||||
color: plateProvider.selectedWeights.contains(number)
|
color: plateProvider.selectedPlates.contains(number)
|
||||||
? const Color.fromARGB(255, 82, 226, 236)
|
? const Color.fromARGB(255, 82, 226, 236)
|
||||||
: const Color.fromARGB(255, 97, 105, 101),
|
: const Color.fromARGB(255, 97, 105, 101),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
child: Text (
|
child: Text(
|
||||||
'$number lbs', // Add unit to text
|
'$number lbs', // Add unit to text
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
@@ -141,34 +142,35 @@ late AnimationController _controller;
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: (){
|
onPressed: () {
|
||||||
plateProvider.saveIntoSharedPrefs();
|
plateProvider.saveIntoSharedPrefs();
|
||||||
if(plateProvider.selectedWeights.isNotEmpty){
|
Navigator.pop(context);
|
||||||
plateProvider.plateChoiceExists=true;
|
|
||||||
plateProvider.calculatePlates();
|
|
||||||
}
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
},
|
||||||
child: const Text('Done'),
|
child: const Text('Done'),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: (){
|
onPressed: () {
|
||||||
|
plateProvider.selectAllPlates();
|
||||||
|
},
|
||||||
|
child: const Text('Select all'),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
plateProvider.resetPlates();
|
plateProvider.resetPlates();
|
||||||
},
|
},
|
||||||
child: const Text('Reset',style: TextStyle(color: Colors.red,fontWeight: FontWeight.bold))
|
child: const Text('Reset'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,16 +18,18 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:provider/provider.dart' as provider;
|
import 'package:provider/provider.dart' as provider;
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:wger/exceptions/http_exception.dart';
|
import 'package:wger/exceptions/http_exception.dart';
|
||||||
import 'package:wger/helpers/consts.dart';
|
import 'package:wger/helpers/consts.dart';
|
||||||
import 'package:wger/helpers/gym_mode.dart';
|
|
||||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||||
import 'package:wger/models/exercises/exercise.dart';
|
import 'package:wger/models/exercises/exercise.dart';
|
||||||
import 'package:wger/models/workouts/log.dart';
|
import 'package:wger/models/workouts/log.dart';
|
||||||
import 'package:wger/models/workouts/routine.dart';
|
import 'package:wger/models/workouts/routine.dart';
|
||||||
import 'package:wger/models/workouts/set_config_data.dart';
|
import 'package:wger/models/workouts/set_config_data.dart';
|
||||||
import 'package:wger/models/workouts/slot_data.dart';
|
import 'package:wger/models/workouts/slot_data.dart';
|
||||||
|
import 'package:wger/providers/plate_weights.dart';
|
||||||
import 'package:wger/providers/routines.dart';
|
import 'package:wger/providers/routines.dart';
|
||||||
|
import 'package:wger/screens/add_plate_weights.dart';
|
||||||
import 'package:wger/widgets/core/core.dart';
|
import 'package:wger/widgets/core/core.dart';
|
||||||
import 'package:wger/widgets/core/progress_indicator.dart';
|
import 'package:wger/widgets/core/progress_indicator.dart';
|
||||||
import 'package:wger/widgets/routines/forms/reps_unit.dart';
|
import 'package:wger/widgets/routines/forms/reps_unit.dart';
|
||||||
@@ -43,8 +45,7 @@ class LogPage extends StatefulWidget {
|
|||||||
final Routine _workoutPlan;
|
final Routine _workoutPlan;
|
||||||
final double _ratioCompleted;
|
final double _ratioCompleted;
|
||||||
final Map<Exercise, int> _exercisePages;
|
final Map<Exercise, int> _exercisePages;
|
||||||
late Log _log;
|
final Log _log;
|
||||||
final int _iteration;
|
|
||||||
|
|
||||||
LogPage(
|
LogPage(
|
||||||
this._controller,
|
this._controller,
|
||||||
@@ -54,12 +55,10 @@ class LogPage extends StatefulWidget {
|
|||||||
this._workoutPlan,
|
this._workoutPlan,
|
||||||
this._ratioCompleted,
|
this._ratioCompleted,
|
||||||
this._exercisePages,
|
this._exercisePages,
|
||||||
this._iteration,
|
int? iteration,
|
||||||
) {
|
) : _log = Log.fromSetConfigData(_configData)
|
||||||
_log = Log.fromSetConfigData(_configData);
|
..routineId = _workoutPlan.id!
|
||||||
_log.routineId = _workoutPlan.id!;
|
..iteration = iteration;
|
||||||
_log.iteration = _iteration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_LogPageState createState() => _LogPageState();
|
_LogPageState createState() => _LogPageState();
|
||||||
@@ -164,6 +163,9 @@ class _LogPageState extends State<LogPage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
widget._log.weight = newValue;
|
widget._log.weight = newValue;
|
||||||
_weightController.text = newValue.toString();
|
_weightController.text = newValue.toString();
|
||||||
|
context.read<PlateWeights>().setWeight(
|
||||||
|
_weightController.text == '' ? 0 : double.parse(_weightController.text),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} on FormatException {}
|
} on FormatException {}
|
||||||
@@ -182,6 +184,9 @@ class _LogPageState extends State<LogPage> {
|
|||||||
num.parse(value);
|
num.parse(value);
|
||||||
setState(() {
|
setState(() {
|
||||||
widget._log.weight = num.parse(value);
|
widget._log.weight = num.parse(value);
|
||||||
|
context.read<PlateWeights>().setWeight(
|
||||||
|
_weightController.text == '' ? 0 : double.parse(_weightController.text),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
} on FormatException {}
|
} on FormatException {}
|
||||||
},
|
},
|
||||||
@@ -208,6 +213,9 @@ class _LogPageState extends State<LogPage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
widget._log.weight = newValue;
|
widget._log.weight = newValue;
|
||||||
_weightController.text = newValue.toString();
|
_weightController.text = newValue.toString();
|
||||||
|
context.read<PlateWeights>().setWeight(
|
||||||
|
_weightController.text == '' ? 0 : double.parse(_weightController.text),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
} on FormatException {}
|
} on FormatException {}
|
||||||
},
|
},
|
||||||
@@ -366,64 +374,71 @@ class _LogPageState extends State<LogPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget getPlates() {
|
Widget getPlates() {
|
||||||
final plates = plateCalculator(
|
return Consumer<PlateWeights>(
|
||||||
double.parse(_weightController.text == '' ? '0' : _weightController.text),
|
builder: (context, plateProvider, child) => Column(
|
||||||
BAR_WEIGHT,
|
children: [
|
||||||
AVAILABLE_PLATES,
|
Text(
|
||||||
);
|
AppLocalizations.of(context).plateCalculator,
|
||||||
final groupedPlates = groupPlates(plates);
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
|
),
|
||||||
return Column(
|
IconButton(
|
||||||
children: [
|
onPressed: () {
|
||||||
Text(
|
Navigator.of(context)
|
||||||
AppLocalizations.of(context).plateCalculator,
|
.push(MaterialPageRoute(builder: (context) => const AddPlateWeights()));
|
||||||
style: Theme.of(context).textTheme.titleLarge,
|
},
|
||||||
),
|
icon: const Icon(Icons.settings),
|
||||||
SizedBox(
|
),
|
||||||
height: 35,
|
SizedBox(
|
||||||
child: plates.isNotEmpty
|
height: 35,
|
||||||
? Row(
|
child: plateProvider.hasPlates
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
? Row(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
...groupedPlates.keys.map(
|
children: [
|
||||||
(key) => Row(
|
...plateProvider.calculatePlates.entries.map(
|
||||||
children: [
|
(entry) => Row(
|
||||||
Text(groupedPlates[key].toString()),
|
children: [
|
||||||
const Text('×'),
|
Text(entry.value.toString()),
|
||||||
Container(
|
const Text('×'),
|
||||||
decoration: BoxDecoration(
|
Container(
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
color: plateProvider.getColor(entry.key),
|
||||||
),
|
shape: BoxShape.circle,
|
||||||
child: Padding(
|
border: Border.all(color: Colors.black, width: 1),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
),
|
||||||
child: SizedBox(
|
child: Padding(
|
||||||
height: 35,
|
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||||
width: 35,
|
child: SizedBox(
|
||||||
child: Align(
|
height: 35,
|
||||||
alignment: Alignment.center,
|
width: 35,
|
||||||
child: Text(
|
child: Align(
|
||||||
key.toString(),
|
alignment: Alignment.center,
|
||||||
style: const TextStyle(
|
child: Text(
|
||||||
fontWeight: FontWeight.bold,
|
entry.key.toString(),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(width: 10),
|
||||||
const SizedBox(width: 10),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
|
child: MutedText(
|
||||||
|
AppLocalizations.of(context).plateCalculatorNotDivisible,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
)
|
),
|
||||||
: MutedText(
|
const SizedBox(height: 3),
|
||||||
AppLocalizations.of(context).plateCalculatorNotDivisible,
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(height: 3),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1180,6 +1180,15 @@ class MockUserProvider extends _i1.Mock implements _i22.UserProvider {
|
|||||||
returnValueForMissingStub: null,
|
returnValueForMissingStub: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void unitChange() => super.noSuchMethod(
|
||||||
|
Invocation.method(
|
||||||
|
#unitChange,
|
||||||
|
[],
|
||||||
|
),
|
||||||
|
returnValueForMissingStub: null,
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setThemeMode(_i23.ThemeMode? mode) => super.noSuchMethod(
|
void setThemeMode(_i23.ThemeMode? mode) => super.noSuchMethod(
|
||||||
Invocation.method(
|
Invocation.method(
|
||||||
|
|||||||
@@ -592,6 +592,15 @@ class MockUserProvider extends _i1.Mock implements _i17.UserProvider {
|
|||||||
returnValueForMissingStub: null,
|
returnValueForMissingStub: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void unitChange() => super.noSuchMethod(
|
||||||
|
Invocation.method(
|
||||||
|
#unitChange,
|
||||||
|
[],
|
||||||
|
),
|
||||||
|
returnValueForMissingStub: null,
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setThemeMode(_i18.ThemeMode? mode) => super.noSuchMethod(
|
void setThemeMode(_i18.ThemeMode? mode) => super.noSuchMethod(
|
||||||
Invocation.method(
|
Invocation.method(
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import 'package:wger/helpers/json.dart';
|
|||||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||||
import 'package:wger/providers/base_provider.dart';
|
import 'package:wger/providers/base_provider.dart';
|
||||||
import 'package:wger/providers/exercises.dart';
|
import 'package:wger/providers/exercises.dart';
|
||||||
import 'package:wger/providers/routines.dart';
|
|
||||||
import 'package:wger/providers/plate_weights.dart';
|
import 'package:wger/providers/plate_weights.dart';
|
||||||
|
import 'package:wger/providers/routines.dart';
|
||||||
import 'package:wger/screens/gym_mode.dart';
|
import 'package:wger/screens/gym_mode.dart';
|
||||||
import 'package:wger/screens/routine_screen.dart';
|
import 'package:wger/screens/routine_screen.dart';
|
||||||
import 'package:wger/widgets/routines/forms/reps_unit.dart';
|
import 'package:wger/widgets/routines/forms/reps_unit.dart';
|
||||||
|
|||||||
@@ -339,6 +339,15 @@ class MockUserProvider extends _i1.Mock implements _i13.UserProvider {
|
|||||||
returnValueForMissingStub: null,
|
returnValueForMissingStub: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void unitChange() => super.noSuchMethod(
|
||||||
|
Invocation.method(
|
||||||
|
#unitChange,
|
||||||
|
[],
|
||||||
|
),
|
||||||
|
returnValueForMissingStub: null,
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setThemeMode(_i14.ThemeMode? mode) => super.noSuchMethod(
|
void setThemeMode(_i14.ThemeMode? mode) => super.noSuchMethod(
|
||||||
Invocation.method(
|
Invocation.method(
|
||||||
|
|||||||
Reference in New Issue
Block a user