【问题标题】:How to ensure button is always pinned to bottom of slide up panel - Flutter如何确保按钮始终固定在向上滑动面板的底部 - Flutter
【发布时间】:2020-08-03 09:10:35
【问题描述】:

我有以下看法。

无论使用什么设备,我都希望“确认”按钮始终显示在向上滑动面板的底部。如果我使用填充或空容器正确定位在底部,它将在较小的屏幕尺寸上被切断。或者,如果我在较小的屏幕上正确定位,我现在会遇到底部空白的问题。我正在使用我认为可以确保所有小部件都留在安全区域内的安全区域小部件?

到目前为止,这是我的代码:


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]

【问题讨论】:

    标签: flutter dart mobile


    【解决方案1】:

    我认为您可以使用 Align 小部件在 Stack 中定位您的小部件。有关更多信息,请参阅此链接中的 link,您将看到示例,包括视频中的说明。

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 2021-07-21
      相关资源
      最近更新 更多