在Scafold的主体中插入扩展的小部件时,我遇到了一个呈现错误。我可以通过使用Container来绕过它,但我更喜欢使用Expanded。
我在一个基本的脚手架上尝试过,没有其他小部件。错误如下:
https://pastebin.com/uzRveb2r
我只在网络上收到这个错误,而不是在手机上。
这是页面代码:
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包装即可。
在中试用此代码https://dartpad.dev/
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!')),
],
))),),
],
),
);
}
}