android - 将网络图像添加到颤振中的问题
问题描述
我正在创建一个颤振壁纸应用程序,我在制作包含某些类别的列表时遇到了问题。图像未加载并且显示此错误 [: package:flutter/src/_newtwork_image_io.dart': failed assertion: line 25 pos 14: 'url != null': is not true。另请参阅 https://flutter.dev/docs/testing/errors ]
可以帮助我吗这是我的应用程序代码这是我的 main.dart :===
// this is my main.dart :
import 'package:flutter/material.dart';
import 'package:wallpaperdex/views/home.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'WallpaperDex',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.white,
),
home: Home(),
);
}
}
这是我的 home.dart 我正在创建我的列表
import 'package:flutter/material.dart';
import 'package:wallpaperdex/data/data.dart';
import 'package:wallpaperdex/model/categorie_model.dart';
import 'package:wallpaperdex/widgets/widget.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
//
List<CategorieModel> categories = new List();
@override
void initState() {
categories = getCategories();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: BrandName(),
elevation: 0.0,
),
body: Container(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(36),
color: Color(0xfff5f8fd),
),
margin: EdgeInsets.symmetric(horizontal: 24),
padding: EdgeInsets.symmetric(horizontal: 20),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: "Search", border: InputBorder.none),
),
),
Icon(Icons.search),
],
),
),
SizedBox(
height: 16,
),
Container(
height: 80,
child: ListView.builder(
// padding: ,
itemCount: categories.length,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return CategoriesTile(categories[index].categorieName,
categories[index].imgUrl);
},
),
)
],
),
),
);
}
}
class CategoriesTile extends StatelessWidget {
final String imgUrl, title;
CategoriesTile(this.title, this.imgUrl);
@override
Widget build(BuildContext context) {
return Container(
child: Stack(
children: <Widget>[
Container(
child: Image.network(imgUrl),
),
Container(
child: Text(title),
),
],
),
);
}
}
这是我的 data.dart:
import 'package:wallpaperdex/model/categorie_model.dart';
List<CategorieModel> getCategories() {
List<CategorieModel> categories = new List();
CategorieModel categorieModel = new CategorieModel();
categorieModel.imgUrl =
"https://images.pexels.com/photos/545008/pexels-photo-545008.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500";
categorieModel.categorieName = "Street Art";
categories.add(categorieModel);
categorieModel = new CategorieModel();
//
categorieModel.imgUrl =
"https://images.pexels.com/photos/704320/pexels-photo-704320.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500";
categorieModel.categorieName = "Wild Life";
categories.add(categorieModel);
categorieModel = new CategorieModel();
//
categorieModel.imgUrl =
"https://images.pexels.com/photos/34950/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=2&w=500";
categorieModel.categorieName = "Nature";
categories.add(categorieModel);
categorieModel = new CategorieModel();
//
categorieModel.imgUrl =
"https://images.pexels.com/photos/466685/pexels-photo-466685.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500";
categorieModel.categorieName = "City";
categories.add(categorieModel);
categorieModel = new CategorieModel();
//
categorieModel.imgUrl =
"https://images.pexels.com/photos/1434819/pexels-photo-1434819.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260";
categorieModel.categorieName = "Motivation";
categories.add(categorieModel);
categorieModel = new CategorieModel();
//
categorieModel.imgUrl =
"https://images.pexels.com/photos/2116475/pexels-photo-2116475.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500";
categorieModel.categorieName = "Bikes";
categories.add(categorieModel);
categorieModel = new CategorieModel();
//
categorieModel.imgUrl =
"https://images.pexels.com/photos/1149137/pexels-photo-1149137.jpeg?auto=compress&cs=tinysrgb&dpr=2&w=500";
categorieModel.categorieName = "Cars";
categories.add(categorieModel);
categorieModel = new CategorieModel();
return categories;
}
这是我的 widget.dart :
import 'package:flutter/material.dart';
// ignore: non_constant_identifier_names
Widget BrandName() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Wallpaper",
style: TextStyle(color: Colors.black87),
),
Text(
"Dex",
style: TextStyle(color: Colors.blue),
)
],
);
}
这是我的 category_model.dart
class CategorieModel {
String categorieName;
String imgUrl;
}
就是这样,这是错误的屏幕截图,请在此处 输入图像描述
解决方案
推荐阅读
- python - 深度学习/Keras:我应该对非常小的数据(输入和输出值)使用非常小的学习率吗?
- javascript - Vuex ReferenceError 未定义。如何正确设置值?
- flutter - Flutter:如何从ongenerate Route注销?
- r - R中的链接分配
- c# - 连接未正确关闭 ASP.NET C#
- cmake - 从 yocto SDK 生成 aarch64 RPM 包
- web - 删除 URL 转发 - Freenom
- google-sheets - Google 表格/Excel:将 IMAGE() 公式转换为纯 URL
- react-native - 在对齐模式下反应原生和阿拉伯文本
- excel - 如何从尚未标准化的大表中提取特定数据?