- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做 Searchview flutter 中的例子
https://github.com/MageshPandian20/Flutter-SearchView
但我想对 进行更改子项类有一个
最终的字符串名称属性;
就我而言,我有一个 Product 类,所以我必须在这个意义上修改代码。
当我运行应用程序时,我收到以下错误:
I/flutter (18897):在构建 IndexFragment(dirty, state:) 时抛出了以下 NoSuchMethodError:
我/flutter (18897):_SearchListState#4f3d3):
I/flutter (18897):方法 'map' 在 null 上被调用。
I/flutter (18897):接收器:空
I/flutter (18897):尝试调用:map(Closure: (Product) => ChildItem)
我不明白为什么我会得到那个错误。在测试和错误的时刻运行应用程序
在 Debug模式下,一切正常,但由于我运行它的方式而有点慢......
我想我省略了一个小细节,但是当我运行应用程序时,我收到了上面提到的错误。
我希望你能帮助我。谢谢你。
*PS:在 Debug模式下运行应用程序时,请检查产品列表是否为空以及列表中每个项目的属性。
我的代码:
import 'package:carousel_pro/carousel_pro.dart';
import 'package:flutter/material.dart';
import 'package:graphqllapp/data/product_data.dart';
import 'package:graphqllapp/modules/product_presenter.dart';
class IndexFragment extends StatefulWidget {
IndexFragment({ Key key }) : super(key: key);
@override
_SearchListState createState() => _SearchListState();
}
class _SearchListState extends State<IndexFragment> implements ProductListView
{
Widget appBarTitle = new Text("Portada", style: new TextStyle(color: Colors.white),);
Icon actionIcon = new Icon(Icons.search, color: Colors.white,);
final key = new GlobalKey<ScaffoldState>();
final TextEditingController _searchQuery = new TextEditingController();
List<Product> _list;
bool isSearching;
String _searchText = "";
ProductListPresenter _presenter;
_SearchListState() {
_presenter = new ProductListPresenter(this);
_presenter.loadProducts();
_searchQuery.addListener(() {
if (_searchQuery.text.isEmpty) {
setState(() {
isSearching = false;
_searchText = "";
});
}
else {
setState(() {
isSearching = true;
_searchText = _searchQuery.text;
});
}
});
}
void init() {
_presenter.loadProducts();
}
@override
void initState() {
super.initState();
init();
isSearching = false;
}
@override
Widget build(BuildContext context) {
return new Column(
children: <Widget>[ new Expanded(
child: new SizedBox(
child: new Carousel(
images: [
new ExactAssetImage('images/glutamina.jpg'),
new ExactAssetImage('images/frasco1.jpg'),
new ExactAssetImage('images/frasco.jpg')]
)
),flex: 2),
new Expanded(
child: new Column(children: <Widget>[
new IconButton(icon: actionIcon, onPressed: () {
setState(() {
if (this.actionIcon.icon == Icons.search) {
this.actionIcon = new Icon(Icons.close, color: Colors.white,);
this.appBarTitle = new TextField(
controller: _searchQuery,
style: new TextStyle(
color: Colors.white,
),
decoration: new InputDecoration(
prefixIcon: new Icon(Icons.search, color: Colors.white),
hintText: "Search...",
hintStyle: new TextStyle(color: Colors.white)
),
);
_handleSearchStart();
} else {
_handleSearchEnd();
}
});
},),new ListView(
padding: new EdgeInsets.symmetric(vertical: 8.0),
children: isSearching ? _buildSearchList() : _buildList(),
)] ),flex : 4)]);
}
List<ChildItem> _buildList() {
return _list.map((product) => new ChildItem(product)).toList();
}
List<ChildItem> _buildSearchList() {
if (_searchText.isEmpty) {
return _list.map((product) => new ChildItem(product)).toList();
} else {
List<Product> _searchList = List();
for (int i = 0; i < _list.length; i++) {
Product product = _list.elementAt(i);
if (product.name.toLowerCase().contains(_searchText.toLowerCase())) {
_searchList.add(product);
}
}
return _searchList.map((product) => new ChildItem(product)).toList();
}
}
void _handleSearchStart() {
setState(() {
isSearching = true;
});
}
void _handleSearchEnd() {
setState(() {
this.actionIcon = new Icon(Icons.search, color: Colors.white,);
this.appBarTitle =
new Text("Search Sample", style: new TextStyle(color: Colors.white),);
isSearching = false;
_searchQuery.clear();
});
}
@override
void onLoadProductsError(String msg) {
// TODO: implement onLoadProductsError
}
@override
void onLoadProductsFinish(List<Product> products) {
// TODO: implement onLoadProductsFinish
_list = products;
}
}
class ChildItem extends StatelessWidget {
final Product product;
ChildItem(this.product);
@override
Widget build(BuildContext context) {
return new ListTile(
leading: new CircleAvatar(
child: Image.memory(product.mainImage),
backgroundColor: Colors.transparent,
),
title: new Text(product.name, style : new TextStyle(fontWeight: FontWeight.bold)),
subtitle: new Text(product.description) ,
isThreeLine: true,
);
}
}
import 'dart:async';
import 'dart:typed_data';
import 'dart:convert';
class Product {
int id;
String name;
String description;
Uint8List mainImage;
Uint8List firstImage;
Uint8List secondImage;
Product({this.id,this.name,this.description,this.mainImage,this.firstImage,this.secondImage});
Product.fromMap(Map<String,dynamic> map)
:id = map["id"],
name = map["name"],
description = map["description"],
mainImage = base64.decode(map["main_image"]),
firstImage = base64.decode(map["first_image"]),
secondImage = base64.decode(map["second_image"]);
}
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:graphqllapp/data/product_data.dart';
class MockProductRepository implements ProductRepository {
@override
Future<List<Product>> fetchProducts() async {
// TODO: implement fetchUsers
String data = await rootBundle.loadString("mockdata/data.json");
var jsonResult = json.decode(data);
return (jsonResult['products'] as List).map((p)=> Product.fromMap(p)).toList();
}
}
import 'package:graphqllapp/data/product_data.dart';
import 'package:graphqllapp/dependency_injection.dart';
abstract class ProductListView {
void onLoadProductsFinish(List<Product> users);
void onLoadProductsError(String msg);
}
class ProductListPresenter {
ProductListView _view;
ProductRepository _repository;
ProductListPresenter(this._view){
_repository = Injector().productRepository;
}
void loadProducts(){
_repository.fetchProducts()
.then((v)=>_view.onLoadProductsFinish(v))
.catchError((onError)=>_view.onLoadProductsError("Error to get users: $onError"));
}
}
最佳答案
该错误似乎是由 _list
引起的正在 null
在通过 onLoadProductsFinish
完成初始化之前.只需声明您的 _list
带有空( []
)列表,它应该可以工作。
List<Product> _list = [];
关于android - flutter - NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52898792/
我正在用来自JSON文件的一些数据填充Flutter中的列表。 但是,我的代码不断抛出异常"NoSuchMethodError (NoSuchMethodError: The method 'add'
通过eclipse运行Tomcat 7报错是: javax.servlet.ServletException: java.lang.NoSuchMethodError: org.eclipse.jdt
这是我的错误行: 这是我的代码: 最佳答案 final jobs= json.decode(response.body)['name_database_table']; 关于mobile - NoSu
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。为了帮助澄清这个问题以便可以重新打开它,visit the help center
我已经被这个错误困扰了几个小时。。我的pom.xml。应用程序未启动。所有的Spring框架依赖于相同的版本,但仍然得到相同的错误。。更新。MVN依赖的结果:树。看起来这里一切都很好。
我得到: NoSuchMethodError: com.foo.SomeService.doSmth()Z 我是否正确理解这个'Z'意味着doSmth()方法的返回类型是 boolean 值?如果为
我在 Speed 类中引用 PlayerUtil.getMovementSpeed(player);,在我的 PlayerUtil 类中,我将方法定义为: public static double g
我得到: NoSuchMethodError: com.foo.SomeService.doSmth()Z 我是否正确理解这个 'Z' 意味着 doSmth() 方法的返回类型是 boolean 值?
我在使用 Spark 和 Scala 时遇到了一个奇怪的错误。我有一段代码声明了一个变量: var offset = 0 这会导致以下异常: java.lang.NoSuchMethodError:
我已经成功实现了 reflectionEquals 方法,其中包含一个排除字段列表。 return EqualsBuilder.reflectionEquals(this, obj, new Str
我正在使用 Spring 框架和 Maven 开发 Java Enterprise 应用程序。我正在为此学习一门类(class),并且一直坚持集成 Hibernate JPA。当我运行项目时,它返回以
I/flutter ( 8282): The following NoSuchMethodError was thrown building Meme(dirty, state: _MemeState
运行以下代码时出现 NoSuchMethodError - 我想从 JSON url 打印出轨道标题 - 我错过了什么吗? import 'dart:async'; import 'dart:conv
我正在做 Searchview flutter 中的例子 https://github.com/MageshPandian20/Flutter-SearchView 但我想对 进行更改子项类有一个 最
尝试从Eclipse中的简单Java程序连接到Hive时出现以下错误。看起来好像连接,然后引发此错误。我可以通过beeline在本地连接到Hive Thrift服务器,而不会出现问题。 两个libth
当我向安全资源发出请求时,会发生NoSuchMethodError。 基于基于Spring Boot 1.4.4的Grails 3.2.5的项目 AppConfig: @EnableWebSecuri
这个问题已经有答案了: Differences between Exception and Error (11 个回答) 已关闭 7 年前。 我的印象是 Exception 非常适合捕获所有可能的异常
祝大家有美好的一天!我使用 google Vision API,当我在 IntelliJ Idea 中运行我的程序时,它工作得很好,但是当我编译 jar 文件时,它在处理照片时给出错误 java.la
我一直在为这个问题苦苦挣扎。我正在开发一个包含很多包的 netbeans java 项目,起初我更改了 gui,但是当我运行代码时,它没有反射(reflect)任何更改,即使我在保存、清理、清理和编译
我一直在寻找问题的解决方案,但没有得到足够的答案。 我正在开发 Bukkit插件的更新系统。因此,我必须自己编写这些类的代码。但我一直想从 debug(String) 调用一个方法(具体来说: ano
我是一名优秀的程序员,十分优秀!