2 Star 23 Fork 13

早起的年轻人 / flutter-ho

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
segment_demo.dart 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
早起的年轻人 提交于 2021-03-17 18:38 . 分段控件
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// 创建人: Created by zhaolong
/// 创建时间:Created by on 3/17/21.
///
/// 可关注公众号:我的大前端生涯 获取最新技术分享
/// 可关注网易云课堂:https://study.163.com/instructor/1021406098.htm
/// 可关注博客:https://blog.csdn.net/zl18603543572
///
/// 代码清单
main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: SegmentPage(),
));
}
class SegmentPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _SegmentPageState();
}
}
class _SegmentPageState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("分段控件"),
),
///填充布局
body: Container(
width: MediaQuery.of(context).size.width,
height: double.infinity,
child: Column(
children: [
buildSegment(),
buildSlidSegment(),
],
),
),
);
}
int _currentIndex = 0;
buildSegment() {
return Container(
margin: EdgeInsets.only(top: 20),
width: 300,
child: CupertinoSegmentedControl(
//子标签
children: <int, Widget>{
0: Text("全部"),
1: Text("收入"),
2: Text("支出 "),
},
//当前选中的索引
groupValue: _currentIndex,
//点击回调
onValueChanged: (int index) {
print("当前选中 $index");
setState(() {
_currentIndex = index;
});
},
//选中的背景颜色
selectedColor: Colors.blue,
//未选中的背景颜色
unselectedColor: Colors.white,
//边框颜色
borderColor: Colors.blue,
//按下的颜色
pressedColor: Colors.blue.withOpacity(0.4),
),
);
}
buildSlidSegment() {
return Container(
margin: EdgeInsets.only(top: 80),
width: 300,
child: CupertinoSlidingSegmentedControl(
//子标签
children: <int, Widget>{
0: Text("全部"),
1: Text("收入"),
2: Text("支出 "),
},
//当前选中的索引
groupValue: _currentIndex,
//点击回调
onValueChanged: (int index) {
print("当前选中 $index");
setState(() {
_currentIndex = index;
});
},
),
);
}
}
1
https://gitee.com/android.long/flutter-ho.git
git@gitee.com:android.long/flutter-ho.git
android.long
flutter-ho
flutter-ho
main

搜索帮助