Flutter &引用';边界半径!=零I/颤振(28205):| |削波器!=空';:“这不是真的”;为什么我会犯这个错误?
我试图从api中获取数据,并将其显示在我的卡片列表中。但是,每当我加载应用程序时,就会出现此错误Flutter &引用';边界半径!=零I/颤振(28205):| |削波器!=空';:“这不是真的”;为什么我会犯这个错误?,flutter,Flutter,我试图从api中获取数据,并将其显示在我的卡片列表中。但是,每当我加载应用程序时,就会出现此错误 'borderRadius != null I/flutter (28205): || clipper != null': is not true. 我不知道如何解决这个问题 我已尝试在发生错误的行中进行更改,但错误保持不变 import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:news/mo
'borderRadius != null
I/flutter (28205): || clipper != null': is not true.
我不知道如何解决这个问题
我已尝试在发生错误的行中进行更改,但错误保持不变
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:news/model/businessModel.dart';
import 'package:http/http.dart' as http;
class Discover extends StatefulWidget {
final Source source;
Discover({Key key, this.source}) : super(key: key);
@override
_DiscoverState createState() => _DiscoverState();
}
class _DiscoverState extends State<Discover> {
String API_KEY = '0ca85f22bce44565ba4fee8d2224adb5';
Future<List<Articles>> fetchArticleBySource() async {
final response = await http.get(
'https://newsapi.org/v2/top-headlines?
category=business&language=en&apiKey=${API_KEY}');
if (response.statusCode == 200) {
List articles = json.decode(response.body)['articles'];
return articles.map((article) => new
Articles.fromJson(article)).toList();
} else {
throw Exception('Failed to load article list');
}
}
var list_articles;
var refreshKey = GlobalKey<RefreshIndicatorState>();
@override
void initState() {
// TODO: implement initState
super.initState();
refreshListArticle();
}
Future<Null> refreshListArticle() async {
refreshKey.currentState?.show(atTop: false);
setState(() {
list_articles = fetchArticleBySource();
});
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(
left: 15.0,
top: 15.0,
right: 15.0,
),
child: ListView(
children: <Widget>[
topArea(),
SizedBox(
height: 10.0,
),
slideCard(),
SizedBox(
height: 5.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Divider(),
),
recentNews(),
],
),
);
}
Widget topArea() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"WEDNESDAY, NOVEMBER 29",
style: TextStyle(color: Colors.grey, fontWeight:
FontWeight.bold),
),
SizedBox(
height: 5.0,
),
Text(
"TOP NEWS",
style: TextStyle(fontSize: 25.0, fontWeight: FontWeight.bold),
),
],
),
Hero(
tag: 'img',
child: InkWell(
//onTap: () => Navigator.push(context, MaterialPageRoute(builder:
(context) => )),
child: CircleAvatar(
radius: 25.0,
//backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(
"https://images.pexels.com/photos/1138409/pexels-photo-
1138409.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260",
),
),
),
),
],
);
}
Widget slideCard() {
return FutureBuilder<List<Articles>>(
future: list_articles,
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text("${snapshot.error}");
} else if (snapshot.hasData) {
List<Articles> articles = snapshot.data;
return Container(
height: 310.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(0.0),
),
child: ListView(
scrollDirection: Axis.horizontal,
children: articles
.map((article) => GestureDetector(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Card(
elevation: 3.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: ClipRRect(
clipper: ,
child: article.urlToImage != null
? Image.network(article.urlToImage)
: Image.asset('images/logo.jpg'),
),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text("${article.title}",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 12.0,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"${article.description}",
style: TextStyle(
color: Colors.black,
fontSize: 14.0,
fontWeight: FontWeight.bold),
),
),
],
),
))
.toList(),
),
);
}
return CircularProgressIndicator();
},
);
}
Widget recentNews() {
return Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Recent News",
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
),
Align(
alignment: Alignment.centerRight,
child: Text(
"See All",
style: TextStyle(color: Colors.lightBlueAccent),
),
)
],
),
),
SizedBox(
height: 7.0,
),
Container(
height: 200.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Card(
elevation: 3.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: ClipRRect(
child: Image.network(
"https://images.pexels.com/photos/935789/pexels-photo-935789.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"),
borderRadius: BorderRadius.circular(10.0),
),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"STARTUPS",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 12.0,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"Top startups that are \nchanging the way we travel",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold),
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Card(
elevation: 3.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: ClipRRect(
child: Image.network(
"https://images.pexels.com/photos/935789/pexels-photo-935789.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"),
borderRadius: BorderRadius.circular(10.0),
),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"STARTUPS",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 12.0,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"Top startups that are \nchanging the way we travel",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold),
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Card(
elevation: 3.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: ClipRRect(
child: Image.network(
"https://images.pexels.com/photos/935789/pexels-photo-935789.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"),
borderRadius: BorderRadius.circular(10.0),
),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"STARTUPS",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 12.0,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"Top startups that are \nchanging the way we travel",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold),
),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Card(
elevation: 3.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: ClipRRect(
child: Image.network(
"https://images.pexels.com/photos/935789/pexels-photo-935789.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260"),
borderRadius: BorderRadius.circular(10.0),
),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"STARTUPS",
style: TextStyle(
color: Colors.blueAccent,
fontSize: 12.0,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Text(
"Top startups that are\n changing the way we travel",
style: TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold),
),
),
],
),
],
),
),
],
);
}
}
导入'dart:convert';
进口“包装:颤振/材料.省道”;
导入“包:news/model/businessModel.dart”;
将“package:http/http.dart”导入为http;
类发现扩展了StatefulWidget{
最终来源;
Discover({Key-Key,this.source}):super(Key:Key);
@凌驾
_DiscoverState createState()=>\u DiscoverState();
}
类_DiscoverState扩展状态{
字符串API_键='0ca85f22bce44565ba4fee8d2224adb5';
Future fetchArticleBySource()异步{
最终响应=等待http.get(
'https://newsapi.org/v2/top-headlines?
category=business&language=en&apiKey=${API_KEY}');
如果(response.statusCode==200){
List articles=json.decode(response.body)['articles'];
return articles.map((article)=>new
Articles.fromJson(article)).toList();
}否则{
抛出异常(“加载项目列表失败”);
}
}
风险价值清单;
var refreshKey=GlobalKey();
@凌驾
void initState(){
//TODO:实现initState
super.initState();
refreshListArticle();
}
Future refreshListArticle()异步{
refreshKey.currentState?显示(atTop:false);
设置状态(){
list_articles=fetchArticleBySource();
});
}
@凌驾
小部件构建(构建上下文){
返回填充(
填充:仅限常量边设置(
左:15.0,
排名:15.0,
右图:15.0,
),
子:ListView(
儿童:[
topArea(),
大小盒子(
身高:10.0,
),
slideCard(),
大小盒子(
身高:5.0,
),
填充物(
填充:仅限常量边集(左:4.0),
子:分隔符(),
),
最新消息(),
],
),
);
}
控件顶部区域(){
返回行(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
纵队(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
正文(
“11月29日,星期三”,
样式:TextStyle(颜色:Colors.grey,fontWeight:
字体(粗体),
),
大小盒子(
身高:5.0,
),
正文(
“头条新闻”,
样式:TextStyle(fontSize:25.0,fontWeight:fontWeight.bold),
),
],
),
英雄(
标签:“img”,
孩子:InkWell(
//onTap:()=>Navigator.push(上下文,MaterialPage路由(生成器:
(上下文)=>),
孩子:圆环星(
半径:25.0,
//背景颜色:颜色。透明,
背景图片:NetworkImage(
"https://images.pexels.com/photos/1138409/pexels-photo-
1138409.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260“,
),
),
),
),
],
);
}
Widget slideCard(){
回归未来建设者(
未来:列出你的文章,
生成器:(上下文,快照){
if(snapshot.hasError){
返回文本(“${snapshot.error}”);
}else if(snapshot.hasData){
列表项目=snapshot.data;
返回容器(
高度:310.0,
装饰:盒子装饰(
边界半径:边界半径。圆形(0.0),
),
子:ListView(
滚动方向:轴水平,
儿童:文章
.map((文章)=>手势检测器(
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
扩大(
孩子:卡片(
标高:3.0,
形状:圆形矩形边框(
边界半径:边界半径。圆形(10.0),
),
孩子:ClipRRect(
克利伯:,
子项:article.urlToImage!=null
?Image.network(article.urlToImage)
:Image.asset('images/logo.jpg'),
),
),
),
大小盒子(
身高:10.0,
),
填充物(
填充:仅限常量边集(左:4.0),
子项:文本(${article.title}),
样式:TextStyle(
颜色:Colors.blueAccent,
字体大小:12.0,
fontWeight:fontWeight.bold),
),
),
大小盒子(
身高:10.0,
),
填充物(
填充:仅限常量边集(左:4.0),
子:文本(
“${article.description}”,
样式:TextStyle(
颜色:颜色,黑色,
字体大小:14.0,
fontWeight:fontWeight.bold),
),
),
],
),
))
.toList(),
),
);
}
返回循环ProgressIndicator();
},
);
}
Widget-recentNews(){
返回列(
儿童:[
填充物(
填充:仅限常量边集(左:4.0),
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
正文(
“最新消息”,
样式:TextStyle(fontSize:20.0,fontWeight:fontWeight.bold),
),
对齐(
对齐:alignment.centerRight,
孩子:T
child: ClipRRect(
clipper: ,
child: article.urlToImage != null
? Image.network(article.urlToImage)
: Image.asset('images/logo.jpg'),
),