ali-azmoud / spinner_input Goto Github PK
View Code? Open in Web Editor NEWA spinner input for flutter. https://pub.dartlang.org/packages/spinner_input
License: Other
A spinner input for flutter. https://pub.dartlang.org/packages/spinner_input
License: Other
When you update the value of the variable affected by a SpinnerInput widget with an action from another widget, at first the value is changed correctly, but then when you use the spinner's buttons again, it acts as though the update never happened.
I don't think I am missing anything about how the SpinnerInput is supposed to be used, and I have tried several things to address this problem, but nothing seems to work.
I have included a complete minimal app below showing the problem, but here is the key bit of the code:
SpinnerInput(
minValue: 1,
maxValue: 50,
step: 1,
spinnerValue: _spinnervalue,
onChange: (value) {setState(() {_spinnervalue = value;});},
),
RaisedButton(
onPressed: () {setState(() {_spinnervalue = initialvalue;});},
child: Text('Clear')
),
In the running app, click the "+" button a few times, say to take the value from 20 up to 25. Then click the "Clear" button -- this sets the value of the spinner back to its initial value of 20. Then click "+" again, just once, and it shows... 26?! It's like you never hit the "Clear" button.
If I'm just doing something wrong here, please let me know, but I think the problem is deeper than that.
Here is the complete Flutter app code:
import 'package:flutter/material.dart';
import 'package:spinner_input/spinner_input.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Spinner Test',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Spinner Test Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double _spinnervalue = 20;
final double _initialvalue = 20;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SpinnerInput(
minValue: 1,
maxValue: 50,
step: 1,
spinnerValue: _spinnervalue,
onChange: (value) {setState(() {_spinnervalue = value;});},
),
RaisedButton(
onPressed: () {setState(() {_spinnervalue = _initialvalue;});},
child: Text('Clear')
),
],
),
),
);
}
}
My use case where this appeared: I have several of these SpinnerInput widgets in an app, and I want to have a single button that the user can click to set all of the spinners back to their initial default values. As seen in the app above, the behavior of the SpinnerInput widget after the action of the button has occurred is not correct for this use.
Would be great to support null-safety in this plugin.
CC @Ali-Azmoud
Hi
I'm submitting the value from keyboard to spinner,then I have to submit it by pressing green button inside spinner..so need 2 submits for a value
is there any fix?
it is possible not to reload the screen when they tap the -+?
Hi, @Ali-Azmoud I have the same problem of #1 with version 0.1.2.
this is my code:
Future<void> _setCustomHours() async {
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Set hours', textAlign: TextAlign.center,),
content: SingleChildScrollView(
child: ListBody(
mainAxis: Axis.vertical,
children: <Widget>[
Padding(
padding: EdgeInsets.only(
top:15.0
),
),
Center(
child: SpinnerInput(
minValue: 1,
maxValue: 10,
step: 0.5,
fractionDigits: 1,
disabledLongPress: true,
disabledPopup: true,
plusButton: SpinnerButtonStyle(
elevation: 3,
height: 40,
width: 40,
color: Colors.grey[300],
textColor: Colors.black,
borderRadius: BorderRadius.circular(3)
),
minusButton: SpinnerButtonStyle(
elevation: 3,
height: 40,
width: 40,
color: Colors.grey[300],
textColor: Colors.black,
borderRadius: BorderRadius.circular(3)
),
middleNumberWidth: 80,
middleNumberStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold
),
spinnerValue: hours, //hours is a double initialized to 1.0 in the State
onChange: (newValue) {
setState(() => hours = newValue);
},
),
),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
},
);
}
When the app starts, I see the value 1.0.
If I tap + or - the value in the state gets updated, while the value I see on the view is still 1.0...
Any idea?
Thanks
I would like to show a percent sign next to the number.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.