how to make multi color gauge in flutter? - 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)
], )
]
)

Related

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

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,
),
);
}

Flutter User ColorFiltered to dark image with matrix

I want in flutter to user ColorFiltered, so i can make jpg image dark here is my code but i didn't get the right result, i don't understand matrix and how to change color this code was from internet, please any idea will be welcome.
ColorFiltered(
child: ColorFiltered(
child: Image.asset(
'myimage.jpg',
fit: BoxFit.fill,
),
colorFilter: ColorFilter.matrix(
[
//R G B A Const
-1, 0, 0, 0, 190, //
0, -1, 0, 0, 255, //
0, 0, -1, 0, 255, //
0, 0, 0, 1, 0, //
],
),
),
colorFilter: ColorFilter.mode(
Colors.white,
BlendMode.darken,
),
)
If you just want to make your image darker the better solution is probably just putting a transparent black Container over your image with a Stack widget:
Stack(children: <Widget>[
Image.network('https://picsum.photos/250?image=9'),
Positioned.fill(
child: Opacity(
opacity: 0.5,
child: Container(
color: const Color(0xFF000000),
),
),
),
]),
If you really want to use ColorFiltered let me know but you can do something like this:
ColorFiltered(
child: Image.network('https://picsum.photos/250?image=9'),
colorFilter: const ColorFilter.mode(
Color(0xFF3D3D3D),
BlendMode.darken,
),
),
Keep in mind that ColorFiltered will not just add a new grey layer over the image. It transforms every pixel of the image separately.
As per the documentation:
This widget applies a function independently to each pixel of child's content, according to the ColorFilter specified.
there is the result based on my search and a little refactoring :
static ColorFilter brightnessAdjust(double value) {
if (value >= 0.0) {
value = value * 255;
} else {
value = value * 100;
}
List<double> matrix;
if (value == 0) {
matrix = identityMatrix;
} else {
matrix = [
1,
0,
0,
0,
value,
0,
1,
0,
0,
value,
0,
0,
1,
0,
value,
0,
0,
0,
1,
0
];
}
return ColorFilter.matrix(matrix);
}
positive value to lighten and negative value to darken (-1 to 1), zero no change anything

Flutter Sparkline Chart double X and Y Axis Bug

im quite new to flutter and having some problems, i could not find in the fl chart documentation
anyone know why my Line Chart shows double X and Y Axis? And how to remove the double axes?
Also the X and Y Axis Values are chaing dynamicly, how can i give them a defined value like 1-1000 and display every 50-Step? so 0,50,100,150 etc ...
Im using FL Chart Library.
Expanded(
child: Container(
padding: EdgeInsets.all(20),
width: double.infinity,
child: LineChart(
LineChartData(
borderData: FlBorderData(show: true),
lineBarsData: [
LineChartBarData(
spots: generateUserLoginData(dashIntranet),
isCurved: false,
barWidth: 2,
colors: [
MD_Blue
]
)
]
)
)
)
)
Sorry for my English, thanks in advance!

How to conditionally render in Flutter

I have a wallet circle which is responsive to the payments that are done. What my issue is when ever the wallet amount is zero, I want the widget that draws the circle to be non visible.
What I did now, is that I used a ternary operatior for checking it inside Custompaint Widget. What am I missing?.
CustomPaint(
painter: (this.total <= 0)
? CurvePainter(colors: [
// To test if the color changes
Colors.red.withOpacity(0.9),
Colors.red.withOpacity(0.9)
], angle: 0, strokeWidth: 0)
: CurvePainter(
colors: [
Colors.white.withOpacity(0.9),
Colors.white.withOpacity(0.9),
],
angle: 360 - ((this.used / this.total) * 360),
strokeWidth: this.strokeWidth,
),
size: Size.fromRadius(strokeWidth),
child: SizedBox(
width: this.radius,
height: this.radius,
),
)
If you want to paint widget conditionally you can use ternary operator like this:
(this.total <= 0)
? CustomPaint(
painter:CurvePainter(
colors: [
Colors.white.withOpacity(0.9),
Colors.white.withOpacity(0.9),
],
angle: 360 - ((this.used / this.total) * 360),
strokeWidth: this.strokeWidth,
),
size: Size.fromRadius(strokeWidth),
child: SizedBox(
width: this.radius,
height: this.radius,
),
) : Container(), // <--- Use it here, not inside CustomPainter
Do you change the variable inside setState?
setState((){
total = 0;
});
setstate rerenders the screen.

Change corner radius in curved CornerStyle in (Syncfusion) Doughnut Chart

I am using syncfusion Pie charts in flutter. I want know know if there is a way to change the scale of the chart inside the parent container without change parent size,
and how to change the radius of the corner when the CornerStyle value is bothCurved
this is my code:
class HalfDoughnutChart extends StatelessWidget {
final List<ChartData> chartData = [
ChartData('David', 30, Color.fromRGBO(9, 0, 136, 1)),
ChartData('Mark', 38, Color.fromRGBO(147, 0, 119, 1)),
ChartData('Test', 34, Color.fromRGBO(228, 0, 124, 1)),
ChartData('Test', 52, Color.fromRGBO(255, 189, 57, 1))
];
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
color: Colors.grey,
height: 250,
width: 500,
child: SfCircularChart(
margin: EdgeInsets.all(0),
legend: Legend(isVisible: true,position: LegendPosition.right),
annotations: <CircularChartAnnotation>[
CircularChartAnnotation(
widget:
Container(
child: const Text('Annotation')
), radius: '2%',
verticalAlignment: ChartAlignment.far,
),
],
series: <CircularSeries>[
DoughnutSeries<ChartData, String>(
dataLabelMapper: (ChartData data, _) => "${data.y.toInt()} %",
dataSource: chartData,
enableSmartLabels: true,
xValueMapper: (ChartData data, _) => data.x,
yValueMapper: (ChartData data, _) => data.y,
pointColorMapper: (ChartData data, _) => data.color,
radius: '70%',
innerRadius: '65%',
startAngle: 270, // Starting angle of doughnut
endAngle: 90,
dataLabelSettings: DataLabelSettings(
// Renders the data label
isVisible: true
),
// Corner style of doughnut segment
cornerStyle: CornerStyle.bothCurve)
]))));
}
}
class ChartData {
ChartData(this.x, this.y, [this.color]);
final String x;
final double y;
final Color color;
}
find chart image in below link:
https://ibb.co/r7MjNBB
thank you
Thanks for the interest in our Flutter charts widget. We have analyzed your queries and find the responses below.
Query #1 Is there a way to change the scale of the chart inside the parent container without change the parent size.
You can use the radius property to customize the size of the chart without changing its parent size. To know more about our charts, please refer to the help document.
Query #2 How to change the radius of the corner when the CornerStyle value is bothCurved?
As of now, you are unable to change the corner radius of each point however you can customize the corner style using the enum property cornerStyle. To know more about rounded corners, find the user guide.
Kindly revert us if you need any further assistance.
Thanks,
Dharanitharan. P