-
Notifications
You must be signed in to change notification settings - Fork 184
Old Radio Dial
Ali-Azmoud edited this page May 7, 2020
·
1 revision
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<FlutterSliderHatchMarkLabel> rDEffects = [];
List<Map<dynamic, dynamic>> mRDEffects = [];
double rdellv = 30;
void initState() {
super.initState();
for (double i = 0; i <= 100; i++) {
mRDEffects.add({"percent": i, "size": 49 + rng.nextInt(50 - 49).toDouble()});
}
rDEffects = updateRDEffects(
ellv * 100 / mRDEffects.length, euuv * 100 / mRDEffects.length);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: EdgeInsets.all(20),
height: 140,
child: FlutterSlider(
rangeSlider: true,
min: 0,
max: effects.length.toDouble(),
values: [ellv, euuv],
handler: FlutterSliderHandler(
decoration: BoxDecoration(),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: Colors.white,
border: Border.all(
color: Colors.black.withOpacity(0.65),
width: 1)),
)),
rightHandler: FlutterSliderHandler(
decoration: BoxDecoration(),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: Colors.white,
border: Border.all(
color: Colors.black.withOpacity(0.65),
width: 1)),
)),
handlerWidth: 6,
handlerHeight: 40,
touchSize: 20,
tooltip: FlutterSliderTooltip(
format: (value) {
return value + ' MHz';
},
textStyle: TextStyle(fontSize: 40),
boxStyle: FlutterSliderTooltipBox(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.black54, width: 1)))),
hatchMark: FlutterSliderHatchMark(
labels: effects,
linesAlignment: FlutterSliderHatchMarkAlignment.right,
density: 0.5,
),
trackBar: FlutterSliderTrackBar(
inactiveTrackBar: BoxDecoration(
borderRadius: BorderRadius.circular(30),
),
activeTrackBarHeight: 2,
inactiveTrackBarHeight: 1,
activeTrackBar: BoxDecoration(
color: Colors.transparent,
)),
onDragging: (a, b, c) {
ellv = b;
euuv = c;
effects = updateEffects(
b * 100 / mEffects.length, c * 100 / mEffects.length);
setState(() {});
}),
),
);
}
List<FlutterSliderHatchMarkLabel> updateRDEffects(
double leftPercent, double rightPercent) {
List<FlutterSliderHatchMarkLabel> newLabels = [];
Color color;
for (Map<dynamic, dynamic> label in mRDEffects) {
double opacity = 1;
if (label['percent'] % 10 == 0) {
newLabels.add(FlutterSliderHatchMarkLabel(
percent: label['percent'],
label: Container(
height: label['size'],
width: 15,
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: Center(
child: Container(
width: 2,
color: Color(0xff999999).withOpacity(opacity),
)),
),
Positioned(
bottom: -20,
left: 0,
right: 0,
child: Center(
child: Container(
width: 40,
child: Text(
(label['percent']).toStringAsFixed(0),
softWrap: false,
style: TextStyle(fontSize: 13, color: Color(0xffeeeeee).withOpacity(opacity)),
),
)),
),
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: Center(
child: Container(
height: 25,
width: 10,
color: Color(0xff222222),
child: Center(
child: Text(
(label['percent'] / 10).toStringAsFixed(0),
softWrap: false,
style: TextStyle(fontSize: 13, color: Color(0xffeeeeee).withOpacity(opacity)),
)),
),
),
),
],
),
)));
} else if(label['percent'] % 2 == 0) {
newLabels.add(FlutterSliderHatchMarkLabel(
percent: label['percent'],
label: Container(
height: label['size'],
width: 3,
child: Stack(
children: <Widget>[
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: Center(
child: Container(
width: 1,
color: Color(0xff777777).withOpacity(opacity),
)),
)
],
),
)));
}
newLabels.add(FlutterSliderHatchMarkLabel(
percent: label['percent'],
label: Container(
height: label['size'],
width: 3,
child: Stack(
children: <Widget>[
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
width: 2,
height: 1,
color: Color(0xff777777).withOpacity(opacity),
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
width: 2,
height: 1,
color: Color(0xff777777).withOpacity(opacity),
),
),
Positioned(
top: 0,
bottom: 0,
left: 0,
right: 0,
child: Center(
child: Container(
width: 2,
height: 1,
color: Color(0xff777777).withOpacity(opacity),
)),
)
],
),
)));
}
return newLabels;
}
}