【问题标题】:Flutter: Image height dynamic will be changed according to text height increase and decreaseFlutter:图片高度动态会根据文字高度的增减而变化
【发布时间】:2020-11-07 18:59:26
【问题描述】:

我在 GridView-builder 索引的顶部设置了一个图像,在底部设置了多行文本。接下来我希望在更改文本行的同时动态更改图像高度大小。 假设,当底部文本行增加时,顶部图像高度将在索引中消失。

 class category_route extends StatelessWidget {


 @override
 Widget build(BuildContext context) {



var sizeDevice = MediaQuery.of(context).size;
final orientation = MediaQuery.of(context).orientation;

final double itemHeight = (sizeDevice.height - kToolbarHeight - 24) / 3;
final double itemWidth = sizeDevice.width / 3;



return MaterialApp(
  home: Scaffold(

    backgroundColor: Colors.yellow,

    body: GridView.builder(
      padding: EdgeInsets.all(8),
      itemCount: categoryTitleArray.length,
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: (orientation == Orientation.portrait) ? 3 : 4,
        crossAxisSpacing: 5,
        mainAxisSpacing: 5,
        childAspectRatio: (itemWidth / itemHeight),
      ),


      itemBuilder: (BuildContext context, int index) {
        return new Card(

        child: new GridTile(
          
            child:  Image.asset(categoryImageArray[index],
            ),
            footer: Text("${categoryTitleArray[index]}"),

          ),
        );
      },
    ),


  ),
);
}
}

【问题讨论】:

    标签: image flutter dart text gridview


    【解决方案1】:

    不要使用 GridTile 请使用这个

    return 
    new Card(
      child: new Column(
        children: [
          Expanded(
            child: Image.network(
              categoryImageArray[index],
            ),
          ),
          Text("${categoryTitleArray[index]}")
        ],
      ),
    );
    

    我对此进行了测试并且运行良好。希望我回答这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-10
      • 2022-12-19
      • 2013-04-09
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      相关资源
      最近更新 更多