對(duì)于想實(shí)現(xiàn)滑動(dòng)按鈕功能的人來說,其實(shí)還是非常簡(jiǎn)單的設(shè)置揩环,如下圖:
實(shí)現(xiàn)這樣功能的代碼其實(shí)不難蝗砾,這里謝了一個(gè)demo,供參考:
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
/**
* 滑動(dòng)按鈕
*/
void main() {
runApp(myApp());
}
class myApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: 'fade demo',
theme: ThemeData(
primarySwatch: Colors.blue
),
home: CupertinoSliderDemo()
);
}
}
class CupertinoSliderDemo extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _CupertinoSliderDemo();
}
}
class _CupertinoSliderDemo extends State<CupertinoSliderDemo>{
double _value = 1.0;
@override
Widget build(BuildContext context) {
// TODO: implement build
return Center(
child: CupertinoSlider(
value: _value,
onChanged: (double value) {
setState(() {
print('$value');
_value = value;
});
},
min: 1.0,
max: 10.0,
divisions: 5,
activeColor: Colors.red,
),
);
}
}