import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:user/account/edit_text.dart';
import 'package:user/health/picker.dart';
import 'package:user/res/gaps.dart';
import 'package:user/routers/fluro_navigator.dart';
import 'package:user/widgets/app_bar.dart';
class DiseasePage extends StatefulWidget {
DiseasePage({Key key, this.count, this.data, this.subData, this.type})
: super(key: key);
final int count; //分区数量
final List data; //分区1
final List subData; //分区2
final int type; //疾病分类 0疾病史 1手术外伤史 2家族史 3过敏史
@override
_DiseasePageState createState() => _DiseasePageState();
}
class _DiseasePageState extends State {
final TextEditingController _textController = TextEditingController();
final FocusNode _textNode = FocusNode();
final TextEditingController _textTowController = TextEditingController();
final FocusNode _textTowNode = FocusNode();
List titles = [
'疾病',
'手术外伤',
'家族病',
'过敏源',
];
List subs = [
'疾病',
'手术外伤',
'家族病成员',
'过敏症状',
];
String yearStr = "2020";
@override
void dispose() {
_textController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: NavigateUpButton(),
elevation: 0,
title: Text("数据采集"),
backgroundColor: Colors.orangeAccent,
actions: [
FlatButton(
textColor: Colors.white,
child: Text("保存", style: TextStyle(fontSize: 18.0)),
onPressed: () {
// NavigatorUtils.goBack(context);
// Navigator.pop(context, "123");
NavigatorUtils.goBackWithParams(context, "result");
},
)
],
),
body: _buildScrollable(_buildBody()),
);
}
Widget _buildScrollable(Widget child) {
return defaultTargetPlatform == TargetPlatform.iOS
? FormKeyboardActions(
child: child,
)
: SingleChildScrollView(
child: child,
);
}
_buildBody() => Container(
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
HeaderView(
title: titles[widget.type],
single: "可多选",
textController: _textController,
textNode: _textNode,
),
Gaps.v24,
DiseaseItemView(
isSingle: false,
),
Gaps.v36,
widget.count == 2
? Container(
child: Column(
children: [
Container(
color: Colors.grey[100],
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 10.0),
),
HeaderView(
title: subs[widget.type],
single: widget.type == 2 ? "单选" : "可多选",
textController: _textTowController,
textNode: _textTowNode,
),
Gaps.v16,
DiseaseItemView(
isSingle: widget.type == 2 ? true : false,
),
Gaps.v50,
],
),
)
: Container(
margin: EdgeInsets.all(15.0),
child: Column(
children: [
Gaps.v10,
Center(
child: Text(
"选择${subs[widget.type]}发生时间",
style: TextStyle(
fontSize: 16.0,
color: Colors.grey,
),
),
),
Gaps.v24,
Center(
child: GestureDetector(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
yearStr,
style: TextStyle(
fontSize: 16.0,
color: Colors.grey,
),
),
Icon(
Icons.arrow_drop_down,
color: Colors.grey,
),
],
),
onTap: () {
print("object");
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) {
return GeneralPicker(
height: 300.0,
pickerList: [
"2016",
"2017",
"2018",
"2019",
"2020",
],
defaultRow: 0,
callBack: (value) =>
showPickerSelected(value),
);
});
},
),
),
Gaps.v10,
Container(
color: Colors.grey[200],
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 1.0),
),
],
),
),
],
),
);
void showPickerSelected(value) async {
setState(() {
yearStr = value;
});
}
}
class DiseaseItemView extends StatefulWidget {
DiseaseItemView({Key key, this.isSingle}) : super(key: key);
final bool isSingle; //
@override
_DiseaseItemViewState createState() => _DiseaseItemViewState();
}
class _DiseaseItemViewState extends State {
List titleList = [
"高血压",
"糖尿病",
"高血脂症",
"冠心病",
"脑卒中",
"甲肝",
"乙肝",
"丙肝",
"痛风",
"脂肪肝",
"鼻炎",
"胃炎",
"乳腺癌",
"肺癌",
"肝癌",
"肾炎",
"心衰",
"心脏病",
"心梗",
"脑梗",
];
int groupValue; // = 1;
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(5.0),
child: Wrap(
spacing: 15.0, // 横向间距
runSpacing: 15.0, // 纵向间距
direction: Axis.horizontal, // 排列方向 默认横向
alignment: WrapAlignment.spaceAround,
children:
widget.isSingle ? getSingleItem(titleList) : getItem(titleList),
),
);
}
List getItem(List history) {
List list = List();
for (var i = 0; i < history.length; i++) {
list.add(DiseaseItem(
title: history[i],
));
}
return list;
}
List getSingleItem(List history) {
return history
.asMap()
.keys
.map((type) => groupValue == type
? buildSingle(
context, history[type], Colors.orangeAccent, Colors.white, type)
: buildSingle(
context, history[type], Colors.grey[200], Colors.grey, type))
.toList();
}
void updateGroupValue(int value) {
setState(() {
groupValue = value;
});
}
// 单选按钮
Widget buildSingle(BuildContext context, String title, Color bgcolor,
Color fontcolor, int value) {
return Container(
height: 35.0,
decoration: BoxDecoration(
color: bgcolor,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: FlatButton(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: Text(
title,
style: TextStyle(fontSize: 15.0, color: fontcolor),
),
onPressed: () => {
setState(() {
updateGroupValue(value);
print('$title');
}),
},
),
);
}
}
// 多选按钮
class DiseaseItem extends StatefulWidget {
DiseaseItem({Key key, this.title}) : super(key: key);
final String title;
@override
_DiseaseItemState createState() => _DiseaseItemState();
}
class _DiseaseItemState extends State {
bool isSelected = false;
@override
Widget build(BuildContext context) {
return Container(
height: 35.0,
decoration: BoxDecoration(
color: isSelected ? Colors.orangeAccent : Colors.grey[200],
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: FlatButton(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: Text(
widget.title,
style: TextStyle(
fontSize: 15.0,
color: isSelected ? Colors.white : Colors.grey,
),
),
onPressed: () => {
setState(() {
isSelected = !isSelected;
print('$widget.title');
}),
},
),
);
}
}
class ButtonColor {
static Color bgColor = Colors.grey[200];
static Color fontColor = Colors.grey;
}
class HeaderView extends StatefulWidget {
HeaderView(
{Key key, this.title, this.textController, this.textNode, this.single})
: super(key: key);
final String title;
final String single;
final TextEditingController textController;
final FocusNode textNode;
@override
_HeaderViewState createState() => _HeaderViewState();
}
class _HeaderViewState extends State {
@override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.max, children: [
Padding(
padding: EdgeInsets.all(15.0),
child: EditText(
key: const Key('disease'),
focusNode: widget.textNode,
controller: widget.textController,
inputType: TextInputType.text,
hintText: "请输入或选择${widget.title}",
),
),
Center(
child: Text(
"常见${widget.title}(${widget.single})",
style: TextStyle(
fontSize: 16.0,
color: Colors.grey,
),
),
),
]);
}
}