Flutter - CircularProgressIndicator max value - flutter

i'm trying to find a way to change max value of CircularProgressIndicator
child: CircularProgressIndicator(
strokeWidth: 10,
value: math().valuePercentage,
backgroundColor:
Color.fromARGB(255, 255, 152, 152),
color: Color.fromARGB(255, 233, 54, 54),
i was trying to do it with some math, but i stuck on this:
class math {
double valuePercentage = kcalData().Target / 10000;
}
for example, we have 3216 kcal and the maximum of CircularProgressIndicator is 1.0, so i decide to devide kcal value by 10000, but i want to make a maximum from my Target value. I'm bad at math, so maybe some of you can get it...
Any ideas? Or maybe there is another way to do this?
edit: maximum of indicator equals 1.0, can't set no more

value: currentValue / totalValue,
currentValue: value which you want to show on your indicator
totalValue: max value of your progressIndicator

Let's say your target 10000. This is the maximum. If you want to find how much is the percentage of 3126 in relation with 10000, then you have to divide 3126 with 10000. If you want to have a different max every time, then divide your value with your max.

Related

Interrupt a line in Chart.js lines

I've a weird situation in chart.js, see the picture
Basically a dataset with 4 date and 4 numbers. All 4 numbers value are 1 (doesnt matter).
But actually the real data need to show just 2 intervals (1/1/2020 -> 2/2/2020) and (3/4/2021->6/6/2021). Basically without the segment in the middle.
In this case there is no way Chart.js would be able to understand to not drawn that segment, all values are 1 in all 4 different dates.
So the only solution in my mind is to sub divide all the intervals so I can place a NaN in the middle and use something like stepped:true for the line. But with a lot of data I basically double the numbers of dates making the graph more confusing.
So the question is.. Is there any way to specify for given point if it's a start or an end ?
Or maybe there is a better approach instead of a single line dataset?
Thank you.
Just pass 2 datasets:
const labels = Utils.months({count: 7});
const data = {
labels: labels,
datasets: [{
label: 'My First Dataset',
data: [65, 59, 80],
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
},{
label: 'My 2nd Dataset',
data: [null, null, null, 81, 56, 55, 40],
fill: false,
borderColor: 'rgb(75, 40, 192)',
tension: 0.1
}]
};
If You pass objects instead of arrays as data, then you do not even have to pad with nulls

how can i replace the original value with another

i have the following code
Listener(
onPointerMove: (detail){
print(detail.position);
}
)
now by default detail.position will give the following
Offest(dy,dx);
now after many test i noticed the max value of dy equal MediaQuery.of(context).size.height
and the same with dx the max value equal MediaQuery.of(context).size.width
lets assume that my MediaQuery.of(context).size.height equal 800 in double, and i wrap my scaffold into Listener widget so if i touch any point (lets say at the bottom at the last point in screen ) so of course i will outputs 800 .
Question what if i want replace the max value with other value lets say from 800 to 1000 ??
in other word when i repeat the same touch process so it will outputs 1000 .
NOTE : i know it is impossible to replace it but i mean I want the output calculations to come based on a maximum value of the value I set and not MediaQuery.of(context).size.height so There is no problem if the value remains the same .
in the fact other value come from image height from server so it is not fixed always it might be even less than original value
i need it the same with width too .
It's purely a math matter
How can i handle with it ?

is it possible for syncfusion chart plotband to have a dynamic associatedAxisEnd value?

I want to be able to have a vertical line from the x-axis to the height of the y value, which is dynamic as it is being taken from a database.
example: for the data point 1 Jan, I want to have a plotband associatedAxisEnd of 45 , 2 Jan associatedAxisEnd of 65 etc...
I'm only able to create a constant associatedAxisEnd height currently, is there a way to be able to loop through the chart data and set the associatedAxisEnd height dynamically?
primaryXAxis: CategoryAxis(
axisLine: const AxisLine(width: 3),
majorGridLines: const MajorGridLines(width: 0,
color: Colors.transparent),
plotBands:
<PlotBand>[
PlotBand(
isVisible: true,
isRepeatable: true,
repeatEvery: 2,
size: 1,
borderWidth: 1,
repeatUntil: 6,
associatedAxisEnd: 50, // is it possible to have a loop on this line?
borderColor: Colors.grey,
dashArray : const <double>[5, 5]
),
]
)
You cannot have a loop when setting values for the PlotBand’s associatedAxisEnd property. However, you can achieve your requirement by adding individual plot band lines for the chart data points as per required.
We have created a simple sample in which we have added plot band lines for the chart data points by lopping through the chart data and attached the sample below for reference. Also appended the user guide documentation link for plot line rendering below for reference.
https://help.syncfusion.com/flutter/cartesian-charts/axis-customization#plot-line
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/i404038-1323531402

Flutter: Syncfusion charts how to explicitly set number of x axis labels to show

I'm using this library to show charts in my app.
With my data, the x-axis is always a DateTime
All I want to do is explicitly set the x-axis labels to show and WHERE to show them if possible, e.g.
Show 2 or 4 labels evenly spaced, beginning (so centred under the y-axis) and at end of the x-axis
Like this:
or this:
Here's what I have so far which doesn't quite work, but I'm not sure why:
return DateTimeAxis(
dateFormat: (showXAxisAsName) ? DateFormat("MMM") : DateFormat("dd/MM"),
majorGridLines: MajorGridLines(width: 0),
majorTickLines: MajorTickLines(width: 0),
axisLine: AxisLine(
width: 1,
color: (axesColour != null) ? axesColour : GTColors.lightGrey,
),
labelStyle: GTTextStyle.caption2.copyWith(
color: (axesColour != null) ? axesColour : GTColors.lightGrey,
),
minimum: (hasData) ? DateTime(first.year, first.month) : null,
maximum: (hasData) ? DateTime(last.year, last.month) : null,
intervalType: DateTimeIntervalType.months,
);
We suggest you the axisLabelFormatter to customize the axis label style and text based on your requirement,if you want to show only the first and last label then you can return the empty string in this callback except for the first and last label. In another way you have to set the interval property in the axis it defines the interval between the data points, so set the interval value based on your requirement.
UG:
• https://help.syncfusion.com/flutter/cartesian-charts/callbacks#axislabelformatter
• https://help.syncfusion.com/flutter/cartesian-charts/axis-types#customizing-interval

Change CircleAvatar size in ListTile

I want to increase the size of an CircleAvatar as Leading of a Listtile. But if i increase the Radius the Circle doesnt keep its ratio and becomes an ellipse.
Here is my Code:
ListView.builder(
itemCount: friendlist.length,
itemBuilder: (BuildContext context, int index) {
print(friendlist[index]);
return ListTile(
title: Text(friendlist[index]["nickname"],
style: TextStyle(fontSize: 20)),
leading: CircleAvatar(
radius: 50,
backgroundColor: Colors.transparent,
backgroundImage: CachedNetworkImageProvider(core.url + "profiles/" + friendlist[index]["avatar_id"]),
),
subtitle:
Text(friendlist[index]["lost_last"])
);
}));
What I tried:
Nesting the Circle Avatar into a Container with fixed Width and Height -> Circle is still an ellipse
Changing the ItemExtent of the ListView.builder -> The Circle still cant use all of the empty space and becomes an ellipse.
Thanks
This is not currently possible with ListTitle, as this is the applied restrictions they have added for the standard of the widget
To be accessible, tappable leading and trailing widgets have to be at
least 48x48 in size. However, to adhere to the Material spec, trailing
and leading widgets in one-line ListTiles should visually be at most
32 (dense: true) or 40 (dense: false) in height, which may conflict
with the accessibility requirement.
You can create custom widget for your requirement.
There is a way to change the CircleAvatar actually , There are two properties related to size: minRadius and maxRadius. The are used to set the minimum and maximum radius respectively. If you already use radius, you are not allowed to use minRadius and/or maxRadius. On the contrary, if either minRadius or maxRadius is set, you are not allowed to use radius :
CircleAvatar(
backgroundImage: NetworkImage('https://www.woolha.com/media/2020/03/eevee.png'),
minRadius: 50,
maxRadius: 75,
)