Slider and Switch

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;
bool selection = true;
@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;
});
}),
Switch(
value: selection,
activeColor: Colors.orange,
inactiveTrackColor: Colors.grey,
activeTrackColor: Colors.lightGreen,
inactiveThumbColor: Colors.black12,
onChanged: (bool val) {
setState(() {
selection = val;
});
}),
],
),
);
}
}
posted @ 2019-06-04 21:08  braveheart007  阅读(108)  评论(0编辑  收藏  举报