我想让男孩的内容颤抖

时间:2020-03-30 15:30:32

标签: flutter

当我尝试将正文的Center小部件包装到SingleChildScrollView中时,出现此问题,并且不再看到页面的内容

 ══════ Exception caught by rendering library ═════════════════════════════════
RenderPositionedBox object was given an infinite size during layout.
The relevant error-causing widget was
    Center 

如果有人可以帮助我将不胜感激 还有我的代码

import 'package:flutter/rendering.dart';

class DetailLivre extends StatefulWidget {
  @override
  _DetailLivreState createState() => _DetailLivreState();
}

class _DetailLivreState extends State<DetailLivre> {
  @override
  Widget build(BuildContext context) {
    final _backgroundColor = Theme.of(context).primaryColor;
    final _tailleWidth = MediaQuery.of(context).size;
    final _couleurIcons = Colors.blueGrey[200];
    return Scaffold(
      backgroundColor: _backgroundColor,
      appBar: AppBar(
        elevation: 0.0,
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back,
            color: _couleurIcons,
          ),
          onPressed: () =>
              Navigator.pop(context), // Me redirige à la page précédante
        ),
        title: Text(
          'My Books',
          style: TextStyle(color: Color(0xFFB0BEC5)),
        ),
      ),
      body: SingleChildScrollView(
              child: Center(
          child: Stack(
            children: <Widget>[
              Positioned(
                  top: _tailleWidth.height / 35,
                  right: _tailleWidth.width / 2.9,
                  child: Container(
                      height: _tailleWidth.height / 5.0,
                      width: _tailleWidth.width / 4.0,
                      decoration: BoxDecoration(
                          image: DecorationImage(
                              fit: BoxFit.fill,
                              image: AssetImage('images/4.jpg'))))),


            ]
          ),
        ),
      ),
      bottomNavigationBar: Container(
        height: 60,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
            topRight: Radius.circular(30),
            topLeft: Radius.circular(30),
          ),
          boxShadow: [
            BoxShadow(color: Colors.black26, spreadRadius: 0, blurRadius: 7.0),
          ],
        ),
        child: BottomAppBar(
          color: _backgroundColor,
          elevation: 10.0,
          shape: CircularNotchedRectangle(),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        elevation: 6.0,
        onPressed: () => setState(() {}),
        child: Icon(
          Icons.play_arrow,
          size: 40.0,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}


但是当SignleChildScrollView与Body的Center小部件包装在一起时,它没有显示白屏

1 个答案:

答案 0 :(得分:0)

要在Stacked中使用Positioned Widget,Stack Widget必须有一些空间。在您的情况下,堆栈为空,也不在父容器内。因此,定位小部件无法正常工作。并且您得到错误的错误消息。 SingleChildScrollView不是错误的原因。

要为堆栈定义空间,您可以做两件事。

  1. 将“堆栈”窗口小部件包装在“容器”窗口小部件中,并为其提供一定的高度宽度。
  2. 或将容器插入堆栈中

容器( 高度:200, 宽度:200, 子代:Stack( 儿童:[ 定位(...) ] ) )