最初の画像でここに示すように、Flutterで子ビューの縮小を達成する方法を知っていますか?私は非常によく仕事を行うgridViewを使用しました。GridViewのように子ビューを縮小するには
2番目の画像では、私は行を使用しましたが、コンテナとコンストレインで試しましたが、うまく機能しませんでした。新しいコンテナ( マージン:CONST EdgeInsets.all(16.0)、
child:new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Container(
padding: const EdgeInsets.all(2.0),
child: new FoodTile(name: "Tile one", onPressed:(bool state){}),
),
new Container(
padding: const EdgeInsets.all(2.0),
child: new FoodTile(name: "Tile two", onPressed:(bool state){}),
),
new Container(
padding: const EdgeInsets.all(2.0),
child: new FoodTile(name: "Tile three", onPressed:(bool state){}),
)
],
)
));
; D
return new GridView.count(
crossAxisCount: 3,
padding: const EdgeInsets.all(16.0),
mainAxisSpacing: 4.0,
shrinkWrap: true,
crossAxisSpacing: 4.0,
children: widget.foodItems.map((FoodViewModel food){
return new FoodTile(
name: food.name,
icon: food.icon
, onPressed: (bool state) {
food.isSelected = state;
widget?.onFoodItemTaped(food, state);
},
);
}).toList(),
);
ここで任意の制約なしに行のコードは、( 子を新しいSingleChildScrollViewを返す
Complete source code to the tile
Thxを。しかし、正方形を保つためにLayoutBuildに貼り付けなければなりませんでした。 (Container)( )制約:new BoxConstraints.tightFor(width:constraints.maxWidth、height:constraints.maxWidth)、 padding:const EdgeInsets():新しいLayoutBuilder(ビルダー:(ビルド:ビルドコンテキストコンテキスト、BoxConstraints制約){ 新しいコンテナを返します。 .}))、) – swissonid
Thxそれを行ったThx:.all(2.0)、 子:新しいFoodTile(名前: "hallo 2"、onPressed :(ブール状態){})、 )しかし、正方形を保つためにLayoutBuildに貼り付けなければなりませんでした。 – swissonid
AspectRatioがそのためにうまくいくかもしれません –