Ahmadre / FlutterIconPicker

An adaptive comprehensive IconPicker for Flutter
MIT License
116 stars 78 forks source link

The method '+' was called on null at search Icon #3

Closed zgramming closed 4 years ago

zgramming commented 4 years ago

I get this error if i can't found icon after search

════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building IconPicker(dirty, dependencies: [_LocalizationsScope-[GlobalKey#62a5e], _InheritedTheme], state: _IconPickerState#db38d):
The method '+' was called on null.
Receiver: null
Tried calling: +(" ")

The relevant error-causing widget was
    MaterialApp 
lib\main.dart:28
When the exception was thrown, this was the stack
#0      Object.noSuchMethod  (dart:core-patch/object_patch.dart:53:5)
#1      _IconPickerState.build 
package:flutter_iconpicker/IconPicker/iconPicker.dart:69
#2      StatefulElement.build 
package:flutter/…/widgets/framework.dart:4619
#3      ComponentElement.performRebuild 
package:flutter/…/widgets/framework.dart:4502
#4      StatefulElement.performRebuild 
package:flutter/…/widgets/framework.dart:4675
...
════════════════════════════════════════════════════════════════════════════════

After i check in your file , I think you forgot to add default noResultText in your constructor.

Error Line

Wrap(
              spacing: 5,
              runSpacing: 10,
              children: IconPicker.iconMap.length != 0
                  ? iconList
                  : [
                      Center(
                        child: Text(widget.noResultsText +
                            ' ' +
                            SearchBar.searchTextController.text),
                      )
                    ]),

Your Constructor

class IconPicker extends StatefulWidget {
  final double iconSize;
  final String noResultsText;
  static Function reload;
  static Map<String, IconData> iconMap;

  IconPicker({this.iconSize, this.noResultsText, Key key}) : super(key: key);

  @override
  _IconPickerState createState() => _IconPickerState();
}

If i added property noResultsText in FlutterIconPicker.showIconPicker(context, iconSize: 40, noResultsText: 'Not found my bro'); error is gone.

I hope you added default noResultText or make it required in your constructor.

Ahmadre commented 4 years ago

Very good point! Thanks I will update this. Sorry wrote it in one day and hadn't the time.

Ahmadre commented 4 years ago

Fixed in 0.8.2: https://pub.dev/packages/flutter_iconpicker