FLutter Dialog setState及 Dialog被输入框挡住的问题

本文探讨了Flutter中Dialog组件在使用setState更新状态以及如何解决Dialog被输入框遮挡的问题。通过使用特定的背景颜色透明组件来包裹Dialog,可以避免输入框阻挡显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.FLutter Dialog setState

使用StatefulBuilder组件,使用setState1方法管理Dialog状态

showDialog(
    context: context,
    builder: (context) {
     return StatefulBuilder(
       builder: (BuildContext context1,
           void Function(void Function()) setState1) {
         return Scaffold(
           backgroundColor: Colors.transparent,
           body: Center(
             child: Container(
               width: 600.px,
               height: 610.px,
               padding: EdgeInsets.all(20.px),
               decoration: BoxDecoration(
                 borderRadius: BorderRadius.circular(30.px),
                 color: Colors.white,
               ),
               child: Column(
                 children: [
                   Text("创建房间"),
                   SizedBox(height: 20.px),
                   Row(
                     mainAxisAlignment: MainAxisAlignment.spaceAround,
                     children: [
                       if (roomList != null)
                         for (var data in roomList!)
                           Column(
                             children: [
                               GestureDetector(
                                 onTap: () {
                                   chooseType = data.type;
                                   print(chooseType);
                                   setState1(() {});
                                 },
                                 child: Container(
                                   child: Image.network(
                                     data.icon,
                                     width: 230.px,
                                   ),
                                   decoration: BoxDecoration(
                                       border:
                                       chooseType == data.type
                                           ? Border.all(
                                           color: Colors
                                               .blueAccent,
                                           width: 3.px)
                          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值