Flutter 如何确保按钮始终固定在向上滑动面板的底部-颤振
我有以下看法 我希望“确认”按钮始终出现在向上滑动面板的底部,无论使用什么设备。如果我使用填充物或空容器在底部正确定位,它将在较小屏幕上被切断。或者,如果我在较小的屏幕上正确定位,我现在会遇到底部空白的问题。我正在使用安全区域小部件,我认为它确保了所有小部件都在安全区域内 以下是我目前的代码:Flutter 如何确保按钮始终固定在向上滑动面板的底部-颤振,flutter,dart,mobile,Flutter,Dart,Mobile,我有以下看法 我希望“确认”按钮始终出现在向上滑动面板的底部,无论使用什么设备。如果我使用填充物或空容器在底部正确定位,它将在较小屏幕上被切断。或者,如果我在较小的屏幕上正确定位,我现在会遇到底部空白的问题。我正在使用安全区域小部件,我认为它确保了所有小部件都在安全区域内 以下是我目前的代码: class ChooseAppointmentView extends StatefulWidget { @override _ChooseAppointmentViewState creat
class ChooseAppointmentView extends StatefulWidget {
@override
_ChooseAppointmentViewState createState() => _ChooseAppointmentViewState();
}
class _ChooseAppointmentViewState extends State<ChooseAppointmentView> {
final List<Appointment> appointmentList = [
Appointment("Monday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Tuesday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Wednesday", DateTime.now(), DateTime.now(), "PM"),
Appointment("Thursday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Friday", DateTime.now(), DateTime.now(), "PM"),
];
DateTime _dateSelected = DateTime.now();
DateTime _initialiseDate = DateTime.now();
@override
Widget build(BuildContext context) {
BorderRadiusGeometry radius = BorderRadius.only(
topLeft: Radius.circular(24.0),
topRight: Radius.circular(24.0),
);
return BaseView<ConfirmDetailsViewModel>(
builder: (context, model, child) => Scaffold(
backgroundColor: AppColours.primaryColour,
body: SafeArea(
child: WillPopScope(
onWillPop: () async {
return false;
},
child: SlidingUpPanel(
maxHeight: MediaQuery.of(context).size.height * .80,
minHeight: 75.0,
parallaxEnabled: true,
parallaxOffset: .5,
panel: Stack(
children: <Widget>[
Center(
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.02),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 30,
height: 5,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius:
BorderRadius.all(Radius.circular(12.0))),
),
],
),
Container(
height: MediaQuery.of(context).size.height * 0.02),
Container(
child: Text(
"Select a date in here.",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 24.0,
),
),
),
Container(
height: MediaQuery.of(context).size.height * 0.05),
Container(
height: 200,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
minimumDate: _initialiseDate,
maximumDate: _initialiseDate.add(Duration(days: 7)),
initialDateTime: _initialiseDate,
onDateTimeChanged: (dateSelected) {
setState(() {
_dateSelected = dateSelected;
});
},
),
),
Container(
height: MediaQuery.of(context).size.height * 0.05),
Container(
height: 50.0,
width: MediaQuery.of(context).size.width - 50,
child: RaisedButton(
onPressed: () async {
//await model.submit();
Navigator.push(
context,
SizeRoute(
page: ChooseAppointmentView(),
),
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),
child: Text('Confirm'),
color: AppColours.primaryLightColour,
textColor: Colors.white,
padding: EdgeInsets.fromLTRB(9, 9, 9, 9),
),
),
],
),
),
],
),
collapsed: Center(
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.02),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 30,
height: 5,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius:
BorderRadius.all(Radius.circular(12.0))),
),
],
),
Container(
height: MediaQuery.of(context).size.height * 0.02),
Container(
decoration: BoxDecoration(
color: Colors.white, borderRadius: radius),
child: Center(
child: Text(
"Select a different date",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
fontSize: 20.0,
),
),
),
),
],
),
),
body: Container(
decoration: BoxDecoration(color: Colors.white),
child: ListView.builder(
padding: EdgeInsets.only(bottom: 100.0),
itemCount: appointmentList.length,
itemBuilder: (BuildContext context, int index) =>
buildAppointmentCards(context, index),
),
),
borderRadius: radius,
),
),
),
),
);
}
Widget buildAppointmentCards(BuildContext context, int index) {
final appointment = appointmentList[index];
return Padding(
padding: const EdgeInsets.all(10.0),
child: Material(
color: Colors.white.withOpacity(0.0),
child: InkWell(
splashColor: Colors.red,
onTap: () {
print('card tapped');
},
child: new Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
gradient: LinearGradient(
colors: [
AppColours.primaryColour,
AppColours.primaryLightColour,
AppColours.primaryLighterColour,
//add more colors for gradient
],
begin: Alignment.topLeft, //begin of the gradient color
end: Alignment.bottomRight, //end of the gradient color
stops: [0, 0.2, 0.5] //stops for individual color
//set the stops number equal to numbers of color
),
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Container(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
child: Row(
children: <Widget>[
Text(
appointment.day,
style:
TextStyle(fontSize: 30.0, color: Colors.white),
),
Spacer(),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 80.0),
child: Row(
children: <Widget>[
Text(
"${DateFormat('hh:mm').format(appointment.date).toString()} - ${DateFormat('hh:mm').format(appointment.date).toString()}",
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
Spacer(),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
children: <Widget>[
Text(
DateFormat(
'dd/MM/yyyy',
).format(appointment.date).toString(),
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
Spacer(),
Text(
appointment.ampm,
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
],
),
)
],
),
),
),
),
),
),
);
}
}
[enter link description here][2]
类ChooseAppointView扩展StatefulWidget{
@凌驾
_ChooseAppointViewState createState()=>\u ChooseAppointViewState();
}
类_chooseAppointViewState扩展状态{
最终名单任命名单=[
约会(“星期一”,DateTime.now(),DateTime.now(),“上午”),
约会(“星期二”,DateTime.now(),DateTime.now(),“上午”),
约会(“星期三”,DateTime.now(),DateTime.now(),“下午”),
约会(“星期四”,DateTime.now(),DateTime.now(),“上午”),
约会(“星期五”,DateTime.now(),DateTime.now(),“下午”),
];
DateTime _dateSelected=DateTime.now();
DateTime _initialiseDate=DateTime.now();
@凌驾
小部件构建(构建上下文){
BorderRadius几何体半径=BorderRadius.only(
左上:半径。圆形(24.0),
右上角:半径。圆形(24.0),
);
返回基本视图(
生成器:(上下文、模型、子项)=>Scaffold(
背景色:AppColor.PrimaryColor,
正文:安全区(
孩子:Willposcope(
onWillPop:()异步{
返回false;
},
孩子:滑梯(
maxHeight:MediaQuery.of(context).size.height*.80,
最小身高:75.0,
视差控制:对,
视差偏移:.5,
面板:堆栈(
儿童:[
居中(
子:列(
儿童:[
容器(
高度:MediaQuery.of(上下文).size.height*0.02),
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
宽度:30,
身高:5,,
装饰:盒子装饰(
颜色:颜色。灰色[300],
边界半径:
边界半径所有(半径圆形(12.0)),
),
],
),
容器(
高度:MediaQuery.of(上下文).size.height*0.02),
容器(
子:文本(
“在此处选择日期。”,
样式:TextStyle(
fontWeight:fontWeight.normal,
字体大小:24.0,
),
),
),
容器(
高度:MediaQuery.of(上下文).size.height*0.05),
容器(
身高:200,
孩子:Cupertinodepicker(
模式:CupertinodeTatePickerMode.date,
最小日期:_initialiseDate,
最大日期:_initialiseDate.add(持续时间(天):7)),
initialDateTime:_initialiseDate,
onDateTimeChanged:(已选择日期){
设置状态(){
_dateSelected=dateSelected;
});
},
),
),
容器(
高度:MediaQuery.of(上下文).size.height*0.05),
容器(
身高:50.0,
宽度:MediaQuery.of(context).size.width-50,
孩子:升起按钮(
onPressed:()异步{
//等待模型。提交();
导航器。推(
上下文
锡泽鲁特(
页面:选择应用点视图(),
),
);
},
形状:圆形矩形边框(
边界半径:边界半径。圆形(25.0),
),
子项:文本('Confirm'),
颜色:AppColor.PrimaryLightColor,
textColor:Colors.white,
填充:从LTRB(9,9,9,9)开始的边缘设置,
),
),
],
),
),
],
),
折叠:中心(
子:列(
儿童:[
容器(
高度:MediaQuery.of(上下文).size.height*0.02),
划船(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
容器(
宽度:30,
身高:5,,
装饰:盒子装饰(
颜色:颜色。灰色[300],
边界半径:
边界半径所有(半径圆形(12.0)),
),