已经给我完成了一个项目,原来的人不见了。我对代码进行了一些更改,此错误在“收藏夹”页面中弹出。而且我只是想了解OG人员所做的事情。
class Favorites extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Provider<Favorites>(
create: (context) => FavoriteModel(),
builder: (context) {
return favorites(context.watch<FavoriteModel>());});
return Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Text("Favorite Houses"),
Expanded(
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: favorites.houses.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => DetailScreen(
favorites.houses[index],
)),
);
},
child: Container(
padding: EdgeInsets.all(17),
height: 250,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerRight,
child: Container(
width: MediaQuery.of(context).size.width *
.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(20)),
image: DecorationImage(
image: ExactAssetImage(favorites
.houses[index].imagePath),
fit: BoxFit.cover),
boxShadow: [
BoxShadow(
blurRadius: 7,
spreadRadius: 1,
color: Colors.black12,
)
]),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.transparent,
Colors.transparent,
Colors.black87
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
borderRadius: BorderRadius.all(
Radius.circular(20))),
),
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: EdgeInsets.only(
bottom: 12,
left: 40,
right: 12),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: <Widget>[
Container(
width:
MediaQuery.of(context)
.size
.width *
.2,
child: Text(
"${favorites.houses[index].titleTxt}",
style: TextStyle(
fontWeight:
FontWeight.bold,
color: Colors.white),
),
),
Container(
padding: EdgeInsets.all(6),
child: FavoriteWidget(
favorites
.houses[index]),
// Icon(
// Icons.directions,
// color: Colors.white,
// size: 20,
// ),
decoration: BoxDecoration(
color: Colors.black38,
borderRadius:
BorderRadius.all(
Radius.circular(
100)),
),
)
],
),
),
)
],
),
),
),
Align(
alignment: Alignment.centerLeft,
child: Container(
width: MediaQuery.of(context).size.width *
.43,
height: 200,
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20)),
boxShadow: [
BoxShadow(
blurRadius: 7,
spreadRadius: 1,
color: Colors.black12,
)
]),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment:
CrossAxisAlignment.end,
children: <Widget>[
// Icon(
// Icons.attach_money,
// size: 18,
// ),
Text(
"${favorites.houses[index].perNight}/",
style: TextStyle(
fontSize: 16.0,
fontWeight:
FontWeight.bold),
),
Text(
"Year",
style: TextStyle(
fontSize: 16.0,
fontWeight:
FontWeight.bold),
),
],
),
Text(
"${favorites.houses[index].subTxt}",
style: TextStyle(
color: Colors.black38,
),
),
Row(
children: <Widget>[
//RatingBar
Text(
"${favorites.houses[index].reviews}",
style: TextStyle(
fontSize: 10.0,
fontWeight:
FontWeight.bold),
),
],
),
// Row(
// children: <Widget>[],
// ),
Wrap(
children: <Widget>[
...favorites
.houses[index].features
.map((feature) {
return Container(
padding: EdgeInsets.all(6.0),
margin: EdgeInsets.only(
bottom: 6, right: 6),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(
Radius.circular(
50)),
color: Colors.black),
child: Text(
feature,
style: TextStyle(
fontSize: 12,
color: Colors.white),
),
);
})
],
),
],
),
),
)
],
)),
);
}),
),
],
),
);
// return Container(
// margin: const EdgeInsets.all(5),
// padding: const EdgeInsets.all(8.0),
// child: ListView.builder(
// itemCount: house.houses.length,
// itemBuilder: (context, index) {
// return ImageWidget(house.houses[index], house.houses[index].id - 1,
// Constants.imageList);
// }),
// );
});
}
}
在main.dart中找到了这块金块
runApp(ChangeNotifierProvider(
create: (context) => FavoriteModel(), child: MyApp()));
FlutterError.onError = (FlutterErrorDetails details) {
FlutterError.dumpErrorToConsole(details);
if (kReleaseMode) exit(1);
};
runApp(MyApp());
}
因此,基本上,OC创建了收藏夹页面和收藏夹模型,并尝试将其与提供者链接。至少了解我所掌握的知识,但对Flutter / Dart来说,这仍然是新事物,并且至今为止还是很喜欢。