扩展小部件在 Flutter Web 中出现渲染错误
Expanded Widget getting Render Error in Flutter web
我在将 Expanded 小部件插入 Scafold 主体时出现渲染错误。我可以通过使用 Container 来绕过它,但我更愿意使用 Expanded。
我已经在没有其他小部件的基本脚手架中进行了尝试。这是错误:
我只在网络上遇到此错误,在移动设备上没有。
页面代码如下:
import 'package:flutter/material.dart';
import 'package:webenrol/components/enquiries_series.dart';
import 'package:webenrol/constants.dart';
import 'package:webenrol/widgets/enquiries_chart.dart';
class DashboardAdmin extends StatelessWidget {
final List<EnquiriesSeries> data = [
EnquiriesSeries(month: 'Janurary', enquiries: 50),
EnquiriesSeries(month: 'Febuary', enquiries: 75),
EnquiriesSeries(month: 'March', enquiries: 80),
EnquiriesSeries(month: 'April', enquiries: 100),
EnquiriesSeries(month: 'May', enquiries: 120),
EnquiriesSeries(month: 'June', enquiries: 150),
EnquiriesSeries(month: 'July', enquiries: 10),
EnquiriesSeries(month: 'August', enquiries: 50),
EnquiriesSeries(month: 'September', enquiries: 70),
EnquiriesSeries(month: 'October', enquiries: 50),
EnquiriesSeries(month: 'November', enquiries: 130),
EnquiriesSeries(month: 'December', enquiries: 450),
];
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Total Number of Enquiries from X centres',
style: kDashboardCardTitle),
Text(
'546',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Website Enquiries', style: kDashboardCardTitle),
Text(
'10',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Phone Enquiries', style: kDashboardCardTitle),
Text(
'15',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Walk-in Enquiries', style: kDashboardCardTitle),
Text(
'6',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Email Enquiries', style: kDashboardCardTitle),
Text(
'15',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Other Enquiries', style: kDashboardCardTitle),
Text(
'115',
style: kDashboardLargeNumber,
)
],
),
),
),
],
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('History of Enquiries'),
Expanded(child: Text('Hello World!')),
// EnquiriesChart(
// data: data,
// ),
],
))),
],
),
);
}
}
可能是因为您的扩展小部件位于一列中,而该列本身是另一列的子列。
您创建的列本身没有定义高度,可能会因为不知道展开高度而导致错误。
使用定义高度的 SizedBox 或 Container 包裹即可。
中试用此代码
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Store Warehouse',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: DashboardAdmin(),
),
);
}
}
class DashboardAdmin extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
// Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Total Number of Enquiries from X centres',
// ),
// Text(
// '546',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Website Enquiries',),
// Text(
// '10',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Phone Enquiries',),
// Text(
// '15',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Walk-in Enquiries', ),
// Text(
// '6',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Email Enquiries',),
// Text(
// '15',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Other Enquiries',),
// Text(
// '115',
// )
// ],
// ),
// ),
// ),
// ],
// ),
Container(height: 200, child:
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('History of Enquiries'),
Text('History of Enquiries'),
Expanded(child: Text('Hello World!')),
],
))),),
],
),
);
}
}
我在将 Expanded 小部件插入 Scafold 主体时出现渲染错误。我可以通过使用 Container 来绕过它,但我更愿意使用 Expanded。
我已经在没有其他小部件的基本脚手架中进行了尝试。这是错误:
我只在网络上遇到此错误,在移动设备上没有。
页面代码如下:
import 'package:flutter/material.dart';
import 'package:webenrol/components/enquiries_series.dart';
import 'package:webenrol/constants.dart';
import 'package:webenrol/widgets/enquiries_chart.dart';
class DashboardAdmin extends StatelessWidget {
final List<EnquiriesSeries> data = [
EnquiriesSeries(month: 'Janurary', enquiries: 50),
EnquiriesSeries(month: 'Febuary', enquiries: 75),
EnquiriesSeries(month: 'March', enquiries: 80),
EnquiriesSeries(month: 'April', enquiries: 100),
EnquiriesSeries(month: 'May', enquiries: 120),
EnquiriesSeries(month: 'June', enquiries: 150),
EnquiriesSeries(month: 'July', enquiries: 10),
EnquiriesSeries(month: 'August', enquiries: 50),
EnquiriesSeries(month: 'September', enquiries: 70),
EnquiriesSeries(month: 'October', enquiries: 50),
EnquiriesSeries(month: 'November', enquiries: 130),
EnquiriesSeries(month: 'December', enquiries: 450),
];
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Total Number of Enquiries from X centres',
style: kDashboardCardTitle),
Text(
'546',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Website Enquiries', style: kDashboardCardTitle),
Text(
'10',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Phone Enquiries', style: kDashboardCardTitle),
Text(
'15',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Walk-in Enquiries', style: kDashboardCardTitle),
Text(
'6',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Email Enquiries', style: kDashboardCardTitle),
Text(
'15',
style: kDashboardLargeNumber,
)
],
),
),
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('Other Enquiries', style: kDashboardCardTitle),
Text(
'115',
style: kDashboardLargeNumber,
)
],
),
),
),
],
),
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('History of Enquiries'),
Expanded(child: Text('Hello World!')),
// EnquiriesChart(
// data: data,
// ),
],
))),
],
),
);
}
}
可能是因为您的扩展小部件位于一列中,而该列本身是另一列的子列。
您创建的列本身没有定义高度,可能会因为不知道展开高度而导致错误。
使用定义高度的 SizedBox 或 Container 包裹即可。
中试用此代码import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Store Warehouse',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: DashboardAdmin(),
),
);
}
}
class DashboardAdmin extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
// Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Total Number of Enquiries from X centres',
// ),
// Text(
// '546',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Website Enquiries',),
// Text(
// '10',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Phone Enquiries',),
// Text(
// '15',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Walk-in Enquiries', ),
// Text(
// '6',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Email Enquiries',),
// Text(
// '15',
// )
// ],
// ),
// ),
// ),
// Card(
// child: Padding(
// padding: EdgeInsets.all(20.0),
// child: Column(
// children: <Widget>[
// Text('Other Enquiries',),
// Text(
// '115',
// )
// ],
// ),
// ),
// ),
// ],
// ),
Container(height: 200, child:
Card(
child: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text('History of Enquiries'),
Text('History of Enquiries'),
Expanded(child: Text('Hello World!')),
],
))),),
],
),
);
}
}