class name extends StatefulWidget {
name({Key key}) : super(key: key);
@override
_nameState createState() => _nameState();
}
class _nameState extends State<name> {
@override
Widget build(BuildContext context) {
return Container(
child: child, //具体的内容
);
}
}
class DatePicker extends StatefulWidget {
//onCancel/onSure是上个页面传过来的值
DatePicker({Key key, this.onCancel, this.onSure}) : super(key: key);
final Function onSure;
final Function onCancel;
@override
_DatePickerState createState() =>
_DatePickerState(onCancel: this.onCancel, onSure: this.onSure); //传递给_DatePickerState
}
class _DatePickerState extends State<DatePicker> {
final Function onSure;
final Function onCancel;
_DatePickerState({this.onSure, this.onCancel}); //接收DatePicker传过来的值
}
使用DatePicker
使用用法联动地址
DatePicker(
onCancel: () {
Navigator.of(context).pop();
},
onSure: (value) async {
//确认回调
//处理data或业务逻辑
setState(() {
birthday = value;
});
Navigator.pop(context);
// print(value);
},
);
简单的使用方法
child: GestureDetector(
onTap: () {
onCancel();
},
child: Text("取消"),
)
class name extends StatelessWidget {
const name({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
child: child,//具体内容
);
}
}
class IndexCell extends StatelessWidget {
final VoidCallback onPressed;
final String iconName;
final String title;
final String content;
final bool isClick;
IndexCell({this.title, this.content, this.iconName, this.onPressed, this.isClick});
}
IndexCell(
title: '呢称',
content: username,
iconName: null,
isClick: true,
onPressed: () {
//逻辑处理
},
),
简单的使用方法
child: GestureDetector(
onTap: onPressed,
child: Text(content),
)