Flutter : how to create a percent tracker - flutter

I have 10 field on a form and I want have a status tracker similar to the image below..
Basically , I will pass the percent and the widget should be updated
So if 4 items are completed then it will be 40% complete,,
Can you give me some hints on how to create this widget

I think this is somehow weird but may help!
you need a validator
You could make a function called checkProgress() and assign it to the onChanged of the textformfield:
void checkProgress() {
if(textformfieldcontroller.isValid) {
setstate(() {
progressbar = progressbar + 10;
});
} else if (textformfieldcontroller.isNotValid) {
setstate(() {});
}
}
It may work, but if not the concept is using if statements with setstate.

You can use the library percent_indicator
LinearPercentIndicator(animation: true,
lineHeight: 15,
animationDuration: 5000,
percent: 0.4,
backgroundColor: Colors.blue,
progressColor: Colors.orange,
center: Text(
'Text',
style: TextStyle(
color: Theme.of(context).primaryColorDark,
fontSize: 15,
fontWeight: FontWeight.w500),
),
linearStrokeCap: LinearStrokeCap.roundAll,
),
the parameter "percent" shows the progress in the indicator

Related

Reset State of Slide_to_act widget in flutter

I had a problem when I slide my slide_to_act widget it works correctly and it push me to another page. but when I use nav.pop ( when I turn back to old page ) my slide_to_act button looks done. I want to reset it.
SlideAction(
height: 70,
sliderRotate: false,
alignment: Alignment.centerRight,
onSubmit: () {
slideAnimated_push(
context,
ConfirmPage(
total: summedPrice.toInt(), slevee: slevee));
},
innerColor: Colors.white,
outerColor: StGreen,
elevation: 1,
text: 'Slide to Confirm',
textStyle: const TextStyle(
fontFamily: 'RaleWay',
fontSize: 20,
color: Colors.white,
),
),[enter image description here][1]
May be you can reset it after going to the other page.

flutter - percent indicator progressColor

i use percent_indicator package. I wrapped CircularPercentIndicator with Gesturedetetor, i increase start parameter every touch onTap function.
Every time I tap to increase the numeric value by one, the CircularPercentIndicator color starts over. For example; My start parameter is 8 and once I touched it, my start parameter is 9, but the CircularPercentIndicator starts from 0 to 9.
int start = 0;
GestureDetector(
child: CircularPercentIndicator(
radius: 100.0,
lineWidth: 13.0,
animation: true,
percent: start.toDouble() / 100,
center: Text(
start.toString(),
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
footer: const Text(
"Sales this week",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17.0),
),
circularStrokeCap: CircularStrokeCap.round,
progressColor: Colors.purple,
),
onTap: () {
start = start + 1;
setState(() {});
print(start.toString());
},
),
If you check the plugin source code, that is how the plugin is developed, it updates the progress, and runs the _animation.forward(), which will make the animation start from 0 - currentProgress.
I found the solution. There is a property like below.
animateFromLastPercent: true

Obscure text bool value is not updating in flutter

I am using pin_code_text_field package to create pin code textfields. But when I was updating the bool value used to obscure text. Bool value is not updating in pin code fields until I click on textfields.
Code was added below:
bool pinWasObscured = true;
Row(
children: [
PinCodeTextField(
maxLength: 4,
hideCharacter: pinWasObscured,
highlight: true,
highlightAnimation: true,
highlightAnimationBeginColor: Colors.black,
highlightAnimationEndColor: Colors.white,
highlightAnimationDuration: Duration(seconds: 5),
highlightColor: Color(0xFFF37021),
pinBoxDecoration: ProvidedPinBoxDecoration.underlinedPinBoxDecoration,
maskCharacter: "*",
pinTextStyle: TextStyle(
fontSize: 15.sp,
fontWeight: FontWeight.bold,
),
pinBoxWidth: SizeConfig.blockSizeHorizontal! * 12,
pinBoxHeight: SizeConfig.blockSizeHorizontal! * 10,
autofocus: false,
controller: pinController,
defaultBorderColor: Colors.black26,
),
SizedBox(width: 10),
IconButton(
icon: pinWasObscured
? Icon(Icons.visibility_off_outlined)
: Icon(Icons.visibility_outlined),
onPressed: () {
setState(() {
pinWasObscured = !pinWasObscured;
});
},
),
],
),
the issue is that you are also updating the value of the "hideCharacter" on the click of item. you dont have to update the hideCharacter value everytime.
instead you have to set the value to true if you want to hide the character and false to show.

How to pass multiple parameters to a function calling onTap of SfCalender in Flutter?

I am using SfCalender and want to pass one more parameter to a callBack of onTap
SfCalendar(
dataSource: _getDataSource(snapshot.data.data),
view: CalendarView.month,
showNavigationArrow: true,
monthViewSettings: MonthViewSettings(
showAgenda: true,
agendaStyle: AgendaStyle(
backgroundColor: Colors.transparent,
appointmentTextStyle: TextStyle(
color: Colors.white, fontSize: 13, fontStyle: FontStyle.italic),
dateTextStyle: TextStyle(
color: primaryColor, fontSize: 13, fontStyle: FontStyle.italic),
),
),
controller: _calendarController,
onTap: _openForm(array),
)
_openForm(CalendarTapDetails details) {
//code
}
Currently if I dont pass any argument to _openForm, CalenderDetails details have the values but I want to pass one array along with CalenderDetails details. How can I do that?
I don't know the SfCalendar library (and it is closed source), but I think you are trying to do that:
onTap: (details) => _openForm(details, array);
// ...
_openForm(CalendarTapDetails details, List myArray) {
// code
}

Dart - How to a change the color of my raisedButton after clicking in dart?

so i've been struggling to change the color of my button from green to red for my flutter app. Most of the online resources are confusing me. This is my following code.
new RaisedButton(key:null, onPressed:buttonPressed,
color: Colors.green,
child:
new Text(
"10:00 A.M. - 11:00 A.M.",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),void buttonPressed(){
}
I want to click it and it turn green, or even better. Click it, so it turns gray. Then click another button that states "confirm", and it would make all the grey buttons that have been clicked red. Regardless, I'm just trying to understand how to make the button change color after being clicked.
Basically, what you need to do is,
Make RaisedButton color a class-level variable instead of constant as you have now.
Initialize that variable to some color value in initState method.
In the onPressed handler of RaisedButton, do the following:
Change that variable to some color value of your liking.
Trigger Repaint (so that the new color gets painted) i.e. call setState method.
Last but not least, you'll need to have all the code above part of a stateful widget.
Hopefully, it's clear enough, let us know if you'd need some code sample as well.
bool turnToRed = false;
bool colorIsGreen = true;
RaisedButton(key:null, onPressed: (){
setState((){
colorIsGreen = !colorIsGreen;
});
},
color: colorIsGreen ? Colors.green :turnToRed ? Colors.red : Colors.grey,
child:
new Text(
"10:00 A.M. - 11:00 A.M.",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),
RaisedButton(key:null, onPressed: (){
setState((){
turnToRed = !turnToRed;
});
},
color: Colors.red
child:
new Text(
"Confirm",
style: new TextStyle(fontSize:15.0,
color: const Color(0xFF000000),
fontWeight: FontWeight.w200,
fontFamily: "Roboto"),
)
),