我正在创建一个应用程序,当我使用ExpandedTile时出现此错误。你们可以帮我吗?
════════渲染库捕获异常
在performLayout()期间引发了以下断言: BoxConstraints强制无限宽度。
class PlayersTile extends StatelessWidget {
final PlayersData data;
PlayersTile(this.data);
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
child: Row(
children: <Widget>[
Flexible(
flex: 1,
child: Image.network(
data.image,
fit: BoxFit.cover,
height: 150.0,
),
),
Flexible(
flex: 1,
child: Container(
padding: EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
data.name,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 15.0,
),
),
Text(
"DT\$ ${data.points.toString()}",
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 15.0,
fontWeight: FontWeight.bold
),
),
],
),
),
),
ExpansionTile(
children: <Widget>[
Text("teste")
],
)
],
),
),
);
}
}
答案 0 :(得分:1)
您可以在下面复制粘贴运行完整代码
您可以像在ExpansionTile
和Flexible
Image.network
包装Container
和Flexible(
flex: 1,
child: ExpansionTile(
import 'package:flutter/material.dart';
class PlayersData {
String name;
String image;
int points;
PlayersData({this.name, this.image, this.points});
}
class PlayersTile extends StatelessWidget {
final PlayersData data;
PlayersTile(this.data);
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
child: Row(
children: <Widget>[
Flexible(
flex: 1,
child: Image.network(
data.image,
fit: BoxFit.cover,
height: 150.0,
),
),
Flexible(
flex: 1,
child: Container(
padding: EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
data.name,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 15.0,
),
),
Text(
"DT\$ ${data.points.toString()}",
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 15.0,
fontWeight: FontWeight.bold),
),
],
),
),
),
Flexible(
flex: 1,
child: ExpansionTile(
children: <Widget>[Text("teste")],
),
)
],
),
),
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
PlayersTile(PlayersData(
name: "abc",
image: "https://picsum.photos/250?image=9",
points: 10)),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
工作演示
完整代码
const fileName = 'resources/image.png';
const fetched = await fetch(fileName); // Retrieve an image file.
const blob = await fetched.blob(); // Get a blob to represent this image.
const imageBitmap = await createImageBitmap(blob); // Create an imageBitmap from this blob.
const canvas = document.getElementById('canvas'); // Make sure your HTML contains a <canvas> element.
const context = canvas.getContext('2d');
context.drawImage(imageBitmap, 0,0); // Draw this image onto the canvas.