import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/weather_provider.dart';
class BottomListView extends StatelessWidget {
const BottomListView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final weatherData = Provider.of<WeatherProvider>(context).weatherData;
final isLandscape =
MediaQuery.of(context).orientation == Orientation.landscape;
final height = (MediaQuery.of(context).size.height -
50 -
MediaQuery.of(context).padding.top);
return Container(
decoration: const BoxDecoration(
border: Border(
top: BorderSide(width: 0.3, color: Colors.white),
),
color: Color.fromRGBO(255, 255, 255, 0.2),
),
height: isLandscape ? height * 0.35 : null,
child: Row(
children: [
Expanded(
child: SizedBox(
width: 200,
child: ListView(
scrollDirection: Axis.horizontal,
children: [ListTile(title: Text('Hello'))]),
),
),
],
));
}
}
我想擁有帶有 ListTiles 的水平可滾動串列視圖。但沒有 ListTile 它作業正常。使用 ListTile 會導致錯誤。如何解決?我試著給它寬度,但沒有用。
錯誤:
BoxConstraints 強制無限寬度。
這些無效約束由以下函式提供給 RenderParagraph 的 layout() 函式,該函式可能計算了有問題的無效約束:
uj5u.com熱心網友回復:
ListTiles 需要使用 SizedBox 或 Container 顯式定義寬度引數。
如果你不定義寬度,它會拋出無限寬度錯誤。
因此,將您的 ListTile 包裝在 SizedBox 或容器中。
由于ListView 的scrollDirection 設定為Horizo??ntal,因此您不需要將它放在一行內,即它會水平顯示子項。
如果 scrollDirection 設定為垂直,它將在列中顯示子級,即垂直
你也不能兩者都做,使用擴展并給一行的孩子寬度。使用 Expanded 意味著子級將占用其父級可用的最大大小。
試試下面的代碼片段
Container(
decoration: const BoxDecoration(
border: Border(
top: BorderSide(width: 0.3, color: Colors.white),
),
color: Color.fromRGBO(255, 255, 255, 0.2),
),
// height: isLandscape ? height * 0.35 : null,
height: 100,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
SizedBox(
width: 200,
child: ListTile(
title: Text('Hello'),
),
),
SizedBox(
width: 200,
child: ListTile(
title: Text('Hello'),
),
),
SizedBox(
width: 200,
child: ListTile(
title: Text('Hello'),
),
),
SizedBox(
width: 200,
child: ListTile(
title: Text('Hello'),
),
),
],
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/469119.html
標籤:扑
上一篇:將十六進制字串轉換為整數串列
