【问题标题】:How to make the application responsive using Stack and Positoned - Flutter如何使用 Stack 和 Positioned 使应用程序响应式 - Flutter
【发布时间】:2021-10-04 19:46:08
【问题描述】:

如何使用StackPositionedSafeArea中添加形状,我尝试改变AppBar的颜色并连接到形状并添加 mediaQuery,但仍然不是在每个屏幕上都会正确连接。那么如何在SafeArea的整个表面上得到一张svg照片,并且在不使用appbar的情况下使其响应式,是不是需要得到下图这样的效果呢? (代码给出的效果如图,但它不是响应式的,由两部分组成,我想要一个部分并响应)

非常感谢任何帮助。

class Shape extends StatelessWidget {
static Route route() {
return MaterialPageRoute<void>(builder: (_) => Shape());
}

Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    backgroundColor: Colors.blue,
    elevation: 0,
    actions: [],
  ),
  body: _profilePage(context),
);
}

Widget _profilePage(BuildContext context) {
return SafeArea(
  child: Align(
    child: Center(
      child: Stack(
        children: <Widget>[
          Positioned(
            width: MediaQuery.of(context).size.width * 1,
            height: MediaQuery.of(context).size.height,
            bottom: MediaQuery.of(context).size.width * 0.6,
            child: _curved(context),
          ),
        ],
      ),
    ),
  ),
);
}

Widget _curved(BuildContext context) {
return SvgPicture.asset(
  'assets/images/shape_purple.svg',
  color:  Colors.blue,
  allowDrawingOutsideViewBox: true,
);
}

【问题讨论】:

    标签: flutter dart flutter-layout flutter-dependencies flutter-animation


    【解决方案1】:

    改用 FitteBox 小部件

    FittedBox(
                child: Image.asset('assets/images/background.png'),
                fit: BoxFit.fill,
                // decoration: BoxDecoration(
                //     color: Colors.white),
              ),
    

    【讨论】:

    • 当我使用它时,它应该覆盖 SafeArea 吗?并适合每个屏幕?所以它会被用作 AppBar?
    猜你喜欢
    • 2019-01-03
    • 1970-01-01
    • 2020-10-10
    • 2021-08-16
    • 2018-02-01
    • 2021-03-31
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    相关资源
    最近更新 更多