How to achieve expansion of a widget in both vertical (height) and horizontal (width) direction

前端 未结 4 1251
予麋鹿
予麋鹿 2021-02-18 15:30

The code below lays out a chart in which I\'d need to achieve for the chart to be expanded in both vertical (height) and horizontal (width) direction. The suggested method (e.g.

4条回答
  •  眼角桃花
    2021-02-18 15:39

    There is a better way than nesting Row, Expanded and Column widget. You can use the Container widget with Constraints to BoxConstraints.expand().

    Example Code:

        Widget build(BuildContext context) {
          return Container(
            constraints: BoxConstraints.expand(), 
            child: FutureBuilder(
              future: loadImage(),
              builder: (BuildContext context, AsyncSnapshot snapshot) {
                switch(snapshot.connectionState) {
                  case ConnectionState.waiting : 
                    return Center(child: Text("loading..."),);
                  default:
                    if (snapshot.hasError) {
                      return Center(child: Text("error: ${snapshot.error}"),);
                    } else {
                      return ImagePainter(image: snapshot.data);
                    }
                  }
                },
              ),
          );
        }
    

提交回复
热议问题