服务器上 运行 时 Flutter GridView 不显示
Flutter GridView not showing when running on server
这是我在本地 运行 时在我的应用程序中使用的 GridView:
在这里,当我在服务器上构建 (flutter build web) 和 运行 时:
我在浏览器的控制台中收到此错误:
TypeError: Instance of 'minified:jO': type 'minified:jO' is not a
subtype of type 'minified:fC' main.dart.js:11277 at Object.c
(http://localhost/web/main.dart.js:10095:3) main.dart.js:11277 at
Object.az8 (http://localhost/web/main.dart.js:10740:18)
main.dart.js:11277 at iR.aMx [as a]
(http://localhost/web/main.dart.js:10735:3) main.dart.js:11277 at
eR.tq (http://localhost/web/main.dart.js:63249:6) main.dart.js:11277
at tE.xS (http://localhost/web/main.dart.js:66379:58)
main.dart.js:11277 at tE.ep
(http://localhost/web/main.dart.js:66299:3) main.dart.js:11277 at
tE.ep (http://localhost/web/main.dart.js:66408:3) main.dart.js:11277
at eD.ul (http://localhost/web/main.dart.js:66063:3)
main.dart.js:11277 at eD.eu
(http://localhost/web/main.dart.js:66023:16) main.dart.js:11277 at
eD.iZ (http://localhost/web/main.dart.js:66186:32)
编辑:我添加了 CardTest
的代码
这是我的 GridView 的代码:
Column(
children: [
buildSubheadingText('Mes projets'),
buildVerticalSpace(5.0),
GridView.count(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
childAspectRatio: kIsWeb ? 4/1.3 : 1 /1.4,
//physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
children: [
CardTest(
loadingPercent: 0.25,
title: 'Making History Notes',
subtitle: '20 hours progress',
dueDate: DateTime(2022, 4, 12)
),
卡片测试(
加载百分比:0.25,
标题:'Making History Notes',
subtitle: '20 小时进步',
截止日期:DateTime(2022, 4, 12)
),
卡片测试(
加载百分比:0.25,
标题:'Making History Notes',
subtitle: '20 小时进步',
截止日期:DateTime(2022, 4, 12)
)
)
],
);
这是 CardTest 小部件的代码:
import 'package:flutter/material.dart';
class CardTest extends StatelessWidget {
final double loadingPercent;
final String title;
final String subtitle;
final DateTime dueDate;
CardTest({
required this.loadingPercent,
required this.title,
required this.subtitle,
required this.dueDate
});
@override
Widget build(BuildContext context) {
return Flexible(
child: Container(
color: Colors.amber,
child : Column(
children: [
Text(loadingPercent.toString()),
Text(title),
Text(subtitle),
Text(dueDate.toString()),
],
),
),
);
}
}
来自@MarianoZorrilla 的评论:
我只需要从我的 CardTest 中删除 Flexible。
这是我在本地 运行 时在我的应用程序中使用的 GridView:
在这里,当我在服务器上构建 (flutter build web) 和 运行 时:
我在浏览器的控制台中收到此错误:
TypeError: Instance of 'minified:jO': type 'minified:jO' is not a subtype of type 'minified:fC' main.dart.js:11277 at Object.c (http://localhost/web/main.dart.js:10095:3) main.dart.js:11277 at Object.az8 (http://localhost/web/main.dart.js:10740:18) main.dart.js:11277 at iR.aMx [as a] (http://localhost/web/main.dart.js:10735:3) main.dart.js:11277 at eR.tq (http://localhost/web/main.dart.js:63249:6) main.dart.js:11277
at tE.xS (http://localhost/web/main.dart.js:66379:58) main.dart.js:11277 at tE.ep (http://localhost/web/main.dart.js:66299:3) main.dart.js:11277 at tE.ep (http://localhost/web/main.dart.js:66408:3) main.dart.js:11277
at eD.ul (http://localhost/web/main.dart.js:66063:3) main.dart.js:11277 at eD.eu (http://localhost/web/main.dart.js:66023:16) main.dart.js:11277 at eD.iZ (http://localhost/web/main.dart.js:66186:32)
编辑:我添加了 CardTest
的代码这是我的 GridView 的代码:
Column(
children: [
buildSubheadingText('Mes projets'),
buildVerticalSpace(5.0),
GridView.count(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
childAspectRatio: kIsWeb ? 4/1.3 : 1 /1.4,
//physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
children: [
CardTest(
loadingPercent: 0.25,
title: 'Making History Notes',
subtitle: '20 hours progress',
dueDate: DateTime(2022, 4, 12)
),
卡片测试( 加载百分比:0.25, 标题:'Making History Notes', subtitle: '20 小时进步', 截止日期:DateTime(2022, 4, 12) ), 卡片测试( 加载百分比:0.25, 标题:'Making History Notes', subtitle: '20 小时进步', 截止日期:DateTime(2022, 4, 12) ) ) ], );
这是 CardTest 小部件的代码:
import 'package:flutter/material.dart';
class CardTest extends StatelessWidget {
final double loadingPercent;
final String title;
final String subtitle;
final DateTime dueDate;
CardTest({
required this.loadingPercent,
required this.title,
required this.subtitle,
required this.dueDate
});
@override
Widget build(BuildContext context) {
return Flexible(
child: Container(
color: Colors.amber,
child : Column(
children: [
Text(loadingPercent.toString()),
Text(title),
Text(subtitle),
Text(dueDate.toString()),
],
),
),
);
}
}
来自@MarianoZorrilla 的评论:
我只需要从我的 CardTest 中删除 Flexible。