Android 颤振-无接触误差

Android 颤振-无接触误差,android,dart,flutter,Android,Dart,Flutter,我在Searchview flutter中做这个例子 但是我想对具有 最终字符串名称属性 在我的例子中,我有一个产品类,所以我必须在这个意义上修改代码。 当我运行应用程序时,出现以下错误: I/Flatter(18897):在building IndexFragment(脏,状态)中抛出以下NoSuchMethodError: I/颤振(18897):_SearchListState#4f3d3): I/flatter(18897):在null上调用了方法“map”。 I/颤振(18897):接

我在Searchview flutter中做这个例子 但是我想对具有

最终字符串名称属性

在我的例子中,我有一个产品类,所以我必须在这个意义上修改代码。 当我运行应用程序时,出现以下错误:

I/Flatter(18897):在building IndexFragment(脏,状态)中抛出以下NoSuchMethodError: I/颤振(18897):_SearchListState#4f3d3): I/flatter(18897):在null上调用了方法“map”。 I/颤振(18897):接收器:空 I/flatter(18897):尝试调用:map(Closure:(Product)=>ChildItem)

我不明白为什么我会犯那个错误。在测试和出错的瞬间运行应用程序 在调试模式下,一切正常,但由于我的运行方式有点慢。。。 我想我省略了一个小细节,但是当我运行应用程序时,我得到了上面提到的错误。 我希望你能帮助我。多谢各位

*PS:在调试模式下运行应用程序时,请检查产品列表以及列表中每个项目的属性是否为空

我的代码:

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'包:carousel_pro/carousel_pro.dart';
进口“包装:颤振/材料.省道”;
导入“包:graphqllapp/data/product_data.dart”;
导入“包:graphqllapp/modules/product_presenter.dart”;
类IndexFragment扩展StatefulWidget{
IndexFragment({Key}):super(Key:Key);
@凌驾
_SearchListState createState()=>\u SearchListState();
} 
类_SearchListState扩展状态实现ProductListView
{
Widget appBarTitle=新文本(“Portada”,样式:新文本样式(颜色:Colors.white));
Icon actionIcon=新图标(Icons.search,颜色:Colors.white,);
final key=new GlobalKey();
final TextEditingController _searchQuery=新建TextEditingController();
列表(u List),;
布尔正在研究;
字符串_searchText=“”;
ProductListPresenter\u presenter;
_SearchListState(){
_演示者=新产品列表演示者(此);
_loadProducts();
_searchQuery.addListener((){
if(_searchQuery.text.isEmpty){
设置状态(){
isSearching=假;
_searchText=“”;
});
}
否则{
设置状态(){
isSearching=true;
_searchText=\u searchQuery.text;
});
}
});
}
void init(){
_loadProducts();
}
@凌驾
void initState(){
super.initState();
init();
isSearching=假;
}
@凌驾
小部件构建(构建上下文){
返回新列(
儿童:[新扩大(
孩子:新尺寸的盒子(
儿童:新旋转木马(
图像:[
新ExactAssetImages('images/glutamina.jpg'),
新ExactAssetImages('images/frasco1.jpg'),
新ExactAssetImages('images/frasco.jpg')]
)
),flex:2),
新扩展(
子项:新列(子项:[
新图标按钮(图标:操作图标,按下按钮:(){
设置状态(){
if(this.actionIcon.icon==Icons.search){
this.actionIcon=新图标(Icons.close,颜色:Colors.white,);
this.appBarTitle=新文本字段(
控制器:\u searchQuery,
样式:新文本样式(
颜色:颜色,白色,
),
装饰:新的输入装饰(
前缀图标:新图标(Icons.search,颜色:Colors.white),
hintText:“搜索…”,
hintStyle:新文本样式(颜色:Colors.white)
),
);
_handleSearchStart();
}否则{
_handleSearchEnd();
}
});
},),新列表视图(
填充:新边集。对称(垂直:8.0),
子项:正在搜索?\u buildSearchList():\u buildList(),
)])、弹性:4]);
}
列表_buildList(){
return _list.map((product)=>newchilditem(product)).toList();
}
列表_buildSearchList(){
if(_searchText.isEmpty){
return _list.map((product)=>newchilditem(product)).toList();
}否则{
List _searchList=List();
对于(int i=0;i<\u list.length;i++){
Product Product=_list.elementAt(i);
if(product.name.toLowerCase()包含(_searchText.toLowerCase()){
_搜索列表。添加(产品);
}
}
return _searchList.map((product)=>newchilditem(product)).toList();
}
}
void_handleSearchStart(){
设置状态(){
isSearching=true;
});
}
void_handleSearchEnd(){
设置状态(){
this.actionIcon=新图标(Icons.search,颜色:Colors.white,);
这个是appBarTitle=
新文本(“搜索示例”,样式:新文本样式(颜色:Colors.white),);
isSearching=假;
_searchQuery.clear();
});
}
@凌驾
void onLoadProductsError(字符串消息){
//TODO:实现onLoadProductsError
}
@凌驾
作废onLoadProductsFinish(列出产品){
//TODO:实现onLoadProductsFinish
_列表=产品;
}
}
类ChildItem扩展了无状态小部件{
最终产品;
ChildItem(本产品);
@凌驾
小部件构建(构建上下文){
返回新的ListTile(
领先:新CircleAvatar(
子项:Image.memory(product.mainImage),
背景颜色:颜色。透明,
),
标题:新文本(product.name,style:newtextstyle(fontwweight:fontwweight.bold)),
字幕:新文本(产品说明),
伊斯特里琳:是的,
);
}
} 
产品类别:

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"]);  
}
导入'dart:async';
导入“dart:键入的_数据”;
导入“dart:convert”;
类产品{
int-id;
字符串名;
字符串描述;
UINT8列表主映像;
UINT8列出第一个图像;
UINT8列表二次映像;
乘积({this.id,this.n
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<Product> _list = [];