我正在制作一个基本的购物应用程序。我的想法是制作我的产品的列表图块,以便我可以编辑或删除产品。因此,当我导航到该页面时,它显示了一个空白的白色页面,并出现如图所示的错误 空白屏幕 错误
import 'package:flutter/material.dart';
class UserProductItem extends StatelessWidget {
final String title;
final String imageUrl;
UserProductItem(this.title, this.imageUrl);
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(title),
leading: CircleAvatar(
backgroundImage: NetworkImage(imageUrl),
),
trailing: Row(
children: [
IconButton(
icon: Icon(Icons.edit),
onPressed: () {},
color: Theme.of(context).primaryColor,
),
IconButton(
icon: Icon(Icons.delete),
onPressed: () {},
color: Theme.of(context).errorColor,
)
],
),
);
}
}
Run Code Online (Sandbox Code Playgroud) 该程序中有 2 个错误,如上图所示
Main.dart 文件
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Personal Expenses ',
theme: ThemeData(
primarySwatch: Colors.green,
accentColor: Colors.amber,
//errorColor: Colors.red[700],
fontFamily: 'Quicksand',
textTheme: ThemeData.light().textTheme.copyWith(
title: TextStyle(
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold,
fontSize: 18,
),
button: TextStyle(color: Colors.amber)),
appBarTheme: AppBarTheme(
textTheme: ThemeData.light().textTheme.copyWith(
title: TextStyle(
fontFamily: 'OpenSans',
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => …Run Code Online (Sandbox Code Playgroud) 这是我的 chart.dart 文件
import 'package:flutter/material.dart';
import 'package:udemy_expenses_app/widgets/chart_bar.dart';
import '../models/tanscations.dart';
import 'package:intl/intl.dart';
import './chart_bar.dart';
class Chart extends StatelessWidget {
final List<Transaction> recentTransactions;
Chart(this.recentTransactions);
List<Map<String, Object>> get groupedTransactionValues {
return List.generate(7, (index) {
final weekDay = DateTime.now().subtract(
Duration(
days: index,
),
);
double totalSum = 0.0;
for (var i = 0; i < recentTransactions.length; i++) {
if (recentTransactions[i].date.day == weekDay.day &&
recentTransactions[i].date.month == weekDay.month &&
recentTransactions[i].date.year == weekDay.year) {
totalSum += recentTransactions[i].amount;
}
}
return {
'day': DateFormat.E().format(weekDay).substring(0, 1),
'amount': totalSum, …Run Code Online (Sandbox Code Playgroud)