How to assign active to dots whose position is less than activeStep in im_stepper package? - flutter

I am using im_stepper package to create a component as shown below, and one of the requirements is that the steps passed, the corresponding dot will turn yellow, for example: I have a total of 3 steps, and I am in step 2, then i want step 1 passed will have yellow dot like current step .
Here is my code
buildStepperSection() {
return Center(
child: DotStepper(
fixedDotDecoration: FixedDotDecoration(
color: AppTheme.gray_g2,
strokeColor: AppTheme.gray_g2,
),
indicatorDecoration: IndicatorDecoration(
color: AppTheme.yellowDark,
strokeColor: AppTheme.yellowDark,
),
activeStep: 2,
dotCount: 3,
tappingEnabled: false,
lineConnectorsEnabled: true,
dotRadius: 12.0,
lineConnectorDecoration:
LineConnectorDecoration(color: Colors.grey, strokeWidth: 2.0),
spacing: Get.width * 0.3,
),
);
}

Related

Pie chart issues in flutter

I'm using the fl_chart package to create an interactive Pie Chart for my application. Although the design came out fine, I'm facing the following issues with the functionality:
Tapping on a particular PieChartSectionData doesn't always select it and even tapping repeatedly doesn't help. It's always two out of the three that are tappable. Please note that the functionality works as it should for all the sections but there is no indication suggesting that the section tapped on was clicked. As defined in my code, every tap on a section should increase the radius and it's font size to make it stand out from the rest.
Every time a PieChartSectionData is clicked, it is supposed to navigate to a new page after a delay of 500 milliseconds. Although this works as expected, I cannot seem to come back to the previous page that has the Pie Chart on it using the phone's back button on the very first click. It is only after repeated clicks that it takes me back to the original page.
The chart seems to be clickable even beyond the PieChartSectionData. So like let's say if I tap an inch away from one of the sections, it tends to take me to that other page I need to navigate to. This shouldn't be the case.
Here is my code:
class ToDoListPieState extends State<ToDoListPie> {
int? index;
double? percent;
int? taskCount;
#override
Widget build(BuildContext context) {
final provider = Provider.of<TodaysTaskList>(context).getToDoList;
// TODO: implement build
return Stack(
children: [
PieChart(PieChartData(
borderData: FlBorderData(show: false),
pieTouchData: PieTouchData(
touchCallback: (FlTouchEvent event, pieTouchResponse) {
setState(() {
if (pieTouchResponse == null ||
pieTouchResponse.touchedSection == null) {
index = -1;
}
index = pieTouchResponse!.touchedSection!.touchedSectionIndex;
});
Future.delayed(const Duration(milliseconds: 500), () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => TaskList())); //This here is the event where clicking on a section should take us to the next page
});
print('Index: $index'); //This prints even if we click away from a section
},
),
sectionsSpace: 5,
centerSpaceRadius: 80,
sections: [
PieChartSectionData(
color: Colors.blue,
title: provider['upcoming'].length.toString(),
value: double.parse(provider['upcoming'].length.toString()),
radius: index == 0 ? 40 : 30,
titleStyle: TextStyle(fontSize: index == 0 ? 25 : 16)),
PieChartSectionData(
color: Colors.amber,
title: provider['today'].length.toString(),
value: double.parse(provider['today'].length.toString()),
radius: index == -1 ? 40 : 30,
titleStyle: TextStyle(fontSize: index == -1 ? 25 : 16)),
PieChartSectionData(
color: Colors.red,
title: provider['previous'].length.toString(),
value: double.parse(provider['previous'].length.toString()),
radius: index == 1 ? 40 : 30,
titleStyle: TextStyle(fontSize: index == 1 ? 25 : 16))
])),
Positioned(
left: 0,
top: SizeVariables.getHeight(context) * 0.18,
right: 0,
bottom: 0,
child: Column(
children: [
FittedBox(
fit: BoxFit.contain,
child: Text(
'${provider['upcoming'].length + provider['today'].length + provider['previous'].length}',
style: Theme.of(context)
.textTheme
.bodyText1!
.copyWith(fontSize: 25),
),
),
Text(
'Tasks',
style: Theme.of(context)
.textTheme
.bodyText1!
.copyWith(fontSize: 18),
)
],
),
)
],
);
}
}
Any help will be appreciated!

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

Is there any way to show different color horizontal lines in line chart?

I'm implementing line chart in flutter i have draw the line chart but i need to show horizontal lines in different colors. Is there any way to get that?
Here is the attached image what i want to achieve.
LineChartData(
minX: 0,
maxX: 11,
minY: 0,
maxY: 6,
titlesData: LineTitles.getTitleData(),
gridData: FlGridData(
show: true,
getDrawingHorizontalLine: (value) {
return FlLine(
color: Colors.grey,
strokeWidth: 1,
);
},
drawVerticalLine: true,
getDrawingVerticalLine: (value) {
return FlLine(
color: Colors.grey,
strokeWidth: 1,
);
},
),
borderData: FlBorderData(
show: true,
border: Border.all(color: Colors.grey, width: 1),
),
lineBarsData: [
LineChartBarData(
spots: [
FlSpot(4.9, 5),
FlSpot(6.8, 2.5),
FlSpot(8, 4),
FlSpot(9.5, 3),
FlSpot(11, 4),
],
isCurved: true,
barWidth: 3,
),
],
),[![I need to show the orange and red horizontal lines][1]][1]
Yes you can check gridline colors in fl_chart. You've already used function with which you can modify these colors which is getDrawingHorizontalLine().
getDrawingHorizontalLine: (value) {
if(value == 1) {
return FlLine(
color: Colors.red,
strokeWidth: 2,
);
} else if (value == 2 ) {
return FlLine(
color: Colors.yellow,
strokeWidth: 2,
);
} else {
return FlLine(
color: Colors.grey,
strokeWidth: 2,
);
}
}
Now here as you can see I've added condition that if values are 1 or 2 then gridline colors should be red & yellow respectively. Now this is the ugly way to put condition to change color but you can do it dynamically yourself.
If you want to change vertical gridlines then you should use getDrawingVerticalLine() to change color values.
You can see my screenshot for output below.

how to make multi color gauge in flutter?

How to make this type of gauge in flutter application?
Image
check this library :- fl_chart
it has all the charts and graph and you can customise it as you want
you can use this package :
syncfusion_flutter_gauges
then import this package in your dart file:
import 'package:syncfusion_flutter_gauges/gauges.dart';
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SfRadialGauge(),
),
);
}
Normal radial slider
To create a normal radial slider, we need to disable the labels and ticks properties in the RadialAxis class and set the axis range values in the minimum and maximum properties based on our design needs.
To show 100 percent progress, we need to define the axis’s minimum value as 0 and maximum value as 100 as in the following code example.
SfRadialGauge(
axes: <RadialAxis>[
RadialAxis(minimum: 0,
maximum: 100,
showLabels: false,
showTicks: false,
axisLineStyle: AxisLineStyle(
cornerStyle: CornerStyle.bothCurve,
color: Colors.white30,
thickness: 25),
)
]
)
The range pointer will be the track and the marker pointer will be the thumb for the radial slider. You can also set a gradient for the range pointer as shown in the following code example.
SfRadialGauge(
axes: <RadialAxis>[
RadialAxis(
pointers: <GaugePointer>[
RangePointer(
value: 50,
cornerStyle: CornerStyle.bothCurve,
width: 25,
sizeUnit: GaugeSizeUnit.logicalPixel,
gradient: const SweepGradient(
colors: <Color>[
Color(0xFFCC2B5E),
Color(0xFF753A88)
],
stops: <double>[0.25, 0.75]
)),
MarkerPointer(
value: 50,
enableDragging: true,
markerHeight: 34,
markerWidth: 34,
markerType: MarkerType.circle,
color: Color(0xFF753A88),
borderWidth: 2,
borderColor: Colors.white54)
], )
]
)

Adding new item to List<Widget>

i have this array of widget,
but i need to be able to add more item to it dynamically
How to add more item to this array of widget with a function?
List<Widget> _tabScroll() => [
Tab(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.grey[300], width: 1),
color: Colors.grey[100]
),
padding: EdgeInsets.fromLTRB(12.0, 5.0, 12.0, 5.0),
child: Text(_tab1),
),
),
Tab(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.grey[300], width: 1),
color: Colors.grey[100]
),
padding: EdgeInsets.fromLTRB(12.0, 5.0, 12.0, 5.0),
child: Text(_tab2),
),
),
Tab(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.grey[300], width: 1),
color: Colors.grey[100]
),
padding: EdgeInsets.fromLTRB(12.0, 5.0, 12.0, 5.0),
child: Text(_tab3),
),
),
];
this is the controller for the tab
TabBar _tabBarLabel() => TabBar(
tabs: _tabScroll(),
);
Since you are going to be manipulating a list in your code, here are some other simple list operations that might be able to help you. I created a dartpad file here so that you can play with them, and I marked two that will be helpful to you with your specific question:
https://dartpad.dev/a6f78b9ad58a589e7415d9b1625950b6
// Create firstList and add object to the end of firstList
// THIS ONE will help you with your initial question
List<String> firstList = ['Chicago', 'Santiago', 'São Paulo'];
firstList.add('Tokyo');
// Adds to firstList at index number.(indexed from zero)
// THIS ONE will also help you with your initial question, but if you
// want to be more precise with where you insert your element
firstList.insert(2, 'Mexico City');
// Create secondList and add entire secondList to end of firstList
// THIS ONE will help with your initial question if you decide to make
// changes in bulk. (build secondList first with your changes, and add it to
// your initial list all at once.
List<String> secondList = ['Stockholm', 'Moscow', 'Paris'];
firstList.addAll(secondList);
// Create thirdList and add to firstList at index "0" in firstList
// THIS ONE will help you with your initial question if you need to create
// a list ahead of time and insert it at a specific place all at once.
List<String> thirdList = ['New York', 'San José', 'Buenos Aires'];
firstList.insertAll(0,thirdList);
// Removes specific object in firstList
firstList.remove("San José");
// Removes object at specific index in firstList
firstList.removeAt(0);
// Removes last object in firstList
firstList.removeLast();
// Removes everything between 5 and 7 (where 7 is not inclusive) in firstList
firstList.removeRange(5,7);
// Find the index of a given object in firstList
int bestCity = firstList.indexOf("Chicago");
// Finds index of first object that meets some criteria (in this case, starts with S);
var firstS = firstList.indexWhere((city)=>city.startsWith("S"));
// Same as the previous, but instead of starting at zero, it starts with the index of the included integer
var secondS = firstList.indexWhere((city)=>city.startsWith("S"), firstS + 1);
Replace your getter
List<Tab> get tabs => [
Tab(...),
Tab(...),
Tab(...),
];
with instance variable
List<Tab> tabs = [
Tab(...),
Tab(...),
Tab(...),
];
And use
tabs.add(Tab(...));