简体   繁体   English

如何在 Flutter 的 Scaffold 中删除 Stack-Pageview 上方不必要的空白?

[英]How to remove Unnecessary Blank space above Stack-Pageview inside Scaffold in Flutter?

空格标有箭头 I'm making an on-boarding screen.我正在制作一个入职屏幕。 Everything is working as expected but there is some space above the image as can be seen in the provided image which shouldn't be there.一切都按预期工作,但图像上方有一些空间,从提供的图像中可以看出,不应该存在。 I tried using MediaQuery.removePadding but that didn't help.我尝试使用 MediaQuery.removePadding 但这没有帮助。
Please look at the code and if you can suggest anything please do.请查看代码,如果您可以提出任何建议,请执行。 I had the same problem in another project in which I'm using Scaffold->Column->Expanded...., I'm hoping the solution for both would be similar.我在另一个使用 Scaffold->Column->Expanded.... 的项目中遇到了同样的问题,我希望两者的解决方案是相似的。

class OnBoardingScreen extends StatefulWidget {
  const OnBoardingScreen({Key? key}) : super(key: key);
  static const String id = 'onboard-screen';
  @override
  State<OnBoardingScreen> createState() => _OnBoardingScreenState();
}

class _OnBoardingScreenState extends State<OnBoardingScreen> {
  int _pages = 0;
  final _controller = PageController();
  final store = GetStorage(); 
  onButtonPressed(context) {
    store.write('onBoarding', true);
    return Navigator.pushReplacementNamed(context, MainScreen.id);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Stack(
          children: [
            PageView(
              padEnds: false,
              controller: _controller,
              onPageChanged: ((val) {
                setState(() {
                  _pages = val.toInt();
                });
              }),
              children: [
                OnBoardPage(
                  boardColumn: Column(
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(
                        child: Image.asset(
                          'assets/images/1.png',
                          fit: BoxFit.fill,
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(left: 16.0, bottom: 10),
                        child: Text(
                          'Welcome\nto Fiesto',
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 44,
                              color: Colors.white),
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(left: 16.0),
                        child: Text(
                          'Book restaurants, cafes,\nbanquet halls, marriage halls, etc',
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              fontWeight: FontWeight.normal,
                              fontSize: 22,
                              color: Colors.white),
                        ),
                      ),
                    ],
                  ),
                ),
                OnBoardPage(
                  boardColumn: Column(
                    mainAxisSize: MainAxisSize.max,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(
                        child: Image.asset(
                          'assets/images/2.png',
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(left: 16.0, bottom: 10),
                        child: Text(
                          'Fiesto\nParty Services',
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 44,
                              color: Colors.white),
                        ),
                      ),
                      const Padding(
                        padding: EdgeInsets.only(left: 16.0),
                        child: Text(
                          'Get all kinds of party services and\nsolutions',
                          textAlign: TextAlign.left,
                          style: TextStyle(
                              fontWeight: FontWeight.normal,
                              fontSize: 22,
                              color: Colors.white),
                        ),
                      ),
                    ],
                  ),
                ),
            Positioned.fill(
              bottom: 180,
              child: Align(
                alignment: Alignment.bottomCenter,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    AnimatedSmoothIndicator(
                      //https://pub.dev/smooth_page_indicator
                      activeIndex: _pages,
                      count: 5,
                      effect: const JumpingDotEffect(
                        dotHeight: 16,
                        dotWidth: 16,
                        jumpScale: .7,
                        verticalOffset: 15,
                        dotColor: Colors.grey,
                        activeDotColor: Colors.yellow,
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Positioned(
              right: 16,
              bottom: 120,
              child: TextButton(
                child: const Text(
                  'Skip & Proceed to\nLogin/Signup',
                  textAlign: TextAlign.end,
                  style: TextStyle(
                    color: Color.fromARGB(255, 117, 13, 13),
                    fontSize: 14,
                    decoration: TextDecoration.underline,
                  ),
                ),
                onPressed: () {
                  onButtonPressed(context);
                },
              ),
            ),
            Positioned(
              right: 16,
              bottom: 50,
              width: 150,
              height: 50,
              child: ElevatedButton(
                onPressed: () {
                  if (_pages == 0) {
                    _controller.animateToPage(
                      1,
                      duration: const Duration(milliseconds: 400),
                      curve: Curves.easeInOut,
                    );
                  } else if (_pages == 1) {
                    _controller.animateToPage(
                      2,
                      duration: const Duration(milliseconds: 400),
                      curve: Curves.easeInOut,
                    );
                  } else if (_pages == 2) {
                    _controller.animateToPage(
                      3,
                      duration: const Duration(milliseconds: 400),
                      curve: Curves.easeInOut,
                    );
                  } else if (_pages == 3) {
                    _controller.animateToPage(
                      4,
                      duration: const Duration(milliseconds: 400),
                      curve: Curves.easeInOut,
                    );
                  } else if (_pages == 4) {
                    onButtonPressed(context);
                  }
                },
                child: _pages <= 3
                    ? const Text(
                        'Next',
                        style: TextStyle(fontSize: 22),
                      )
                    : const Text(
                        'Login/Signup',
                        style: TextStyle(fontSize: 22),
                      ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class OnBoardPage extends StatelessWidget {
  final Column? boardColumn;
  const OnBoardPage({Key? key, this.boardColumn}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Color.fromARGB(255, 0, 0, 0),
      child: boardColumn,
    );
  }
}

移除SafeArea或指定 top: false。

You have this problem because the Column widgets have a default你有这个问题,因为Column小部件有一个默认值

mainAxisAlignment: MainAxisAlignment.center

so I am changing it to:所以我将其更改为:

mainAxisAlignment: MainAxisAlignment.start


Also my tests on your code indicate the nature of the image is playing a role.我对您的代码的测试也表明图像的性质正在发挥作用。 Because its works like you want on my images.因为它的作品就像你想要的那样在我的图像上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter中如何去掉PageView的前导空格? - How to remove PageView's leading space in Flutter? 删除导航栏上方不必要的空白 - Remove unnecessary white space above navigation bar 如何去除GridView内LinearLayout中的空白? - How to remove blank space in LinearLayout inside GridView? 如何删除Linearlayout中按钮的空白 - How to remove blank space of button inside Linearlayout 在Scaffold中具有动画的PageView页面上的Flutter Switching FAB - Flutter Switching FAB on PageView Pages with animation in Scaffold 如何在 percent_indicator Flutter 中删除进度指示器下方不必要的填充/空格 - How to remove unnecessary padding/space below the progress indicator in percent_indicator Flutter 如何删除工具栏上方的空间? - How to remove space above toolBar? AlertDIalog 删除不必要的空间 - AlertDIalog Remove unnecessary space 删除 android 片段中回收站视图上方不需要的空白区域 - Remove unwanted blank space above recycler view in android fragment 如何从异常消息堆栈中删除所有不必要的字符? - How to remove all unnecessary characters from Exception message stack?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM