首页 > 解决方案 > 如何创造安全区域的条件?

问题描述

我有以下小部件,它带有TabBarView

          child: Scaffold(
            extendBodyBehindAppBar: true,
            extendBody: true,
            body: Container(
              padding: const EdgeInsets.only(top: 20),
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: AssetImage('assets/images/black-bg.png'),
                  fit: BoxFit.fill,
                ),
              ),
              child: SafeArea(
                child: TabBarView(
                  physics: NeverScrollableScrollPhysics(),
                  children: [
                    SlotScreen(),
                    MapScreen(),
                    DeviceScreen(),
                  ],
                ),
              ),
            ),
            appBar: AppBar(
              title: homeViewModel.slotsSize == 0
                  ? Container()
                  : Row(
                      children: [
                        Container(
                          child: Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: normal12TextGold(
                              tr('slot_1'),
                              color: Colors.white,
                              // color: cubit.selectedSim == SIM.sim1 ? goldDefaultColor : null,
                            ),
                          ),
                          decoration: BoxDecoration(
                            color:
                                currentSlotIndex == 0 ? goldDefaultColor : null,
                            borderRadius: homeViewModel.slotsSize != 0
                                ? BorderRadius.all(
                                    Radius.circular(5),
                                  )
                                : BorderRadius.only(
                                    topLeft: Radius.circular(5),
                                    bottomLeft: Radius.circular(5),
                                  ),
                          ),
                        ).onTap(
                          () {
                            homeViewModel.changeSelectedSlot(0);
                            locator<SlotViewModel>().changeSlotIndex();
                          },
                        ),
                        homeViewModel.slotsSize == 2
                            ?  Container(
                          child: Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: normal12TextGold(
                              tr('slot_2'),
                              color: Colors.white,
                              // color: cubit.selectedSim == SIM.sim1 ? goldDefaultColor : null,
                            ),
                          ),
                          decoration: BoxDecoration(
                            color:
                            currentSlotIndex == 1 ? goldDefaultColor : null,
                            borderRadius: homeViewModel.slotsSize != 0
                                ? BorderRadius.all(
                              Radius.circular(5),
                            )
                                : BorderRadius.only(
                              topLeft: Radius.circular(5),
                              bottomLeft: Radius.circular(5),
                            ),
                          ),
                        ).onTap(
                                () {
                                  homeViewModel.changeSelectedSlot(1);
                                  locator<SlotViewModel>().changeSlotIndex();
                                },
                              )
                            : Container(),
                      ],
                    ),
              actions: [
                IconButton(
                  onPressed: () {
                    homeViewModel.goToSpeedTest();
                  },
                  icon: Image.asset(
                    'assets/icons/speet-tst-ic.png',
                    height: 25,
                  ),
                ),
                IconButton(
                  onPressed: () {
                    homeViewModel.navigateToSettingsScreen();
                  },
                  icon: Icon(IconBroken.Setting),
                ),
              ],
              bottom: TabBar(
                indicatorColor: goldDefaultColor,
                indicator: BoxDecoration(
                  border: Border.all(color: goldDefaultColor, width: 1),
                  shape: BoxShape.rectangle,
                  borderRadius: BorderRadius.circular(50),
                  color: Colors.grey[600],
                ),
                labelColor: goldDefaultColor,
                unselectedLabelColor: Colors.white,
                tabs: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Text(tr('Live')),
                      CircleAvatar(
                        radius: 5.0,
                        backgroundColor: Colors.red,
                      ),
                    ],
                  ),
                  Text(tr('Map')),
                  Text(tr('Device Info')),
                ],
              ),
            ),
          ),

当我在脚手架中添加以下属性时:

            extendBodyBehindAppBar: true,
            extendBody: true,

所以我需要的是,我想在屏幕MapScreen保持安全区域时删除安全区域......

标签: flutterdart

解决方案


这就是我会做的,但我会把 TabBarView 和它所有的孩子放在它自己的类里面

child : extendBody ? SafeArea(the all tree) : TabBarView(...)

推荐阅读