Null检查运算符用于Null值,导致相关错误的小部件是Material App



在我使用listview.builder并添加项目列表(在数据列表中提到)之前,该应用程序一直运行良好。我无法理解到底是什么导致了错误,因为IDE本身没有显示错误。有人能解释一下这里发生了什么,并可能给我一个解决方案吗?

提前感谢!

财务页面:

import 'package:flutter/material.dart';
class FinancePage extends StatefulWidget {
const FinancePage({Key? key}) : super(key: key);
@override
_FinancePageState createState() => _FinancePageState();
}
class _FinancePageState extends State<FinancePage> {
final List<DataTiles> dataList = [
DataTiles(title: "Mobile Home Dealers", subtitle: "Last payment 17 May",color: Colors.deepPurpleAccent.shade50),
DataTiles(title: "Taxicabs and Limousines", subtitle: "Last payment 26 May",color: Colors.lightBlueAccent),
DataTiles(title: "Miscellaneous Apparel and Accessory Shops", subtitle: "Last payment 06 April",color: Colors.redAccent),
DataTiles(title: "Electric, Gas, Sanitary and Water utilities", subtitle: "Last payment 01 May",color: Colors.deepPurpleAccent.shade50),
DataTiles(title: "Misc. General Merchandise", subtitle: "Last payment 01 March",color: Colors.lightBlueAccent),
];
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple.shade800,
body: Column(
children: [
const SizedBox(
height: 100,
),
Padding(
padding: const EdgeInsets.all(10),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
elevation: 3,
child: ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
tileColor: Colors.deepPurpleAccent,
leading: const Text(
"Card balance",
style: TextStyle(color: Colors.white),
),
trailing: FittedBox(
fit: BoxFit.fill,
child: Row(
children: const [
Text(
"0₹",
style: TextStyle(color: Colors.white),
),
Icon(
Icons.arrow_forward_ios,
color: Colors.white,
size: 10,
)
],
),
)),
)),
const Text("PAYMENT CATEGORIES",
style: TextStyle(
color: Colors.grey,
)),
SizedBox(
height: 200,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: dataList.length,
itemBuilder: (context, index) {
return  SizedBox(
width: 170,
child: Card(
child: Column(
children: [
Text(dataList[index].title,
style: const TextStyle(
fontSize: 20,
),
),
Text(dataList[index].subtitle,),
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
color: dataList[index].color,
),
);
}),
),
],
),
);
}
}
class DataTiles {
DataTiles({required this.title, required this.subtitle, required this.color});
final String title;
final String subtitle;
final Color color;
}

main.dart

import 'package:flutter/material.dart';
import 'finance_page.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return  const MaterialApp(
title: 'Flutter Demo',
home: FinancePage(),
);
}
}

导致错误的行是

DataTiles(title: "Mobile Home Dealers", subtitle: "Last payment 17 May",color: Colors.deepPurpleAccent.shade50),
DataTiles(title: "Electric, Gas, Sanitary and Water utilities", subtitle: "Last payment 01 May",color: Colors.deepPurpleAccent.shade50),

删除shade50或在没有shade的情况下更改为另一种颜色,这样就可以了。某些颜色没有Shade50的值,例如deepPurpleAccent和deepPurpleAccent。shade100将为他们工作。在使用shade的之前检查文档

相关内容

  • 没有找到相关文章