import ‘package:flutter/material.dart‘;
void main()=>runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
double reading=0.0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Slider(
value: reading,
min: 0.0,
max: 100.0,
inactiveColor: Colors.grey,
activeColor: Colors.orange,
label: ‘value:$reading‘,
divisions: 10,
onChanged: (data){setState(() {
reading = data;
});})
],
),
);
}
}
原文:https://www.cnblogs.com/braveheart007/p/10976118.html