This commit is contained in:
Tibor Bossanyi 2023-02-16 15:22:17 +01:00
parent 0f58f893e6
commit f44df32f93
4 changed files with 127 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,8 @@
Workout Test and Diet 4 You Common Util Functions
Version 1.0.5
number picker widget
Version 1.0.4
webapi client fixes

122
lib/util/number_picker.dart Normal file
View File

@ -0,0 +1,122 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// ignore: must_be_immutable
class NumberPickerWidget extends StatefulWidget {
final Function(double) onChange;
final int minValue;
final int maxValue;
final int initalValue;
final String unit;
final Color color;
double? fontSize;
double? diameterRatio;
double? itemExtent;
FontWeight? fontWeight;
NumberPickerWidget(
{Key? key,
required this.minValue,
required this.maxValue,
required this.initalValue,
required this.unit,
this.fontSize,
this.diameterRatio,
this.itemExtent,
this.fontWeight,
required this.color,
required this.onChange})
: super(key: key) {
fontSize = fontSize ?? 20;
diameterRatio = diameterRatio ?? 0.85;
itemExtent = itemExtent ?? 30;
fontWeight = fontWeight ?? FontWeight.normal;
}
@override
NumberPickerWidgetState createState() => NumberPickerWidgetState();
}
class NumberPickerWidgetState extends State<NumberPickerWidget> {
late FixedExtentScrollController _scrollController;
double value = 0;
@override
void initState() {
super.initState();
_scrollController = FixedExtentScrollController(initialItem: widget.initalValue);
_scrollController.animateToItem(widget.initalValue, duration: const Duration(milliseconds: 100), curve: Curves.easeIn);
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override
void didUpdateWidget(NumberPickerWidget oldWidget) {
//print("value $value initial ${widget.initalValue}");
if (value == 0) {
_scrollController.animateToItem(widget.initalValue, duration: const Duration(milliseconds: 100), curve: Curves.easeIn);
}
super.didUpdateWidget(oldWidget);
}
Widget durationPicker({bool inSeconds = false, bool inHundredths = false}) {
return CupertinoPicker(
scrollController: _scrollController,
useMagnifier: true,
magnification: 1.2,
diameterRatio: widget.diameterRatio!,
backgroundColor: Colors.transparent,
selectionOverlay: Container(),
onSelectedItemChanged: (x) {
currentData = x.toDouble();
//print("sec" + seconds.toStringAsFixed(2));
setState(() {
value = x.toDouble();
});
widget.onChange(value);
},
itemExtent: widget.itemExtent!,
children: List.generate(
widget.maxValue,
(index) => Text('$index ${widget.unit}',
style: TextStyle(color: widget.color, fontSize: widget.fontSize, fontWeight: widget.fontWeight))),
);
}
double currentData = 0;
@override
Widget build(BuildContext context) {
value = 0;
return Container(
color: Colors.transparent,
width: MediaQuery.of(context).size.width * .40,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
color: Colors.transparent,
width: MediaQuery.of(context).size.width * .35,
child: Center(
child: Container(
color: Colors.transparent,
width: MediaQuery.of(context).size.width * 0.95,
//height: MediaQuery.of(context).size.height * 0.25,
height: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(child: durationPicker()),
],
)),
),
),
],
),
);
}
}

View File

@ -1,6 +1,6 @@
name: workouttest_util
description: Workout Test app and web functions.
version: 1.0.4
version: 1.0.5
homepage:
environment: