I am trying to add a Future ( Selecting Icon ) so I have used this package:
import 'package:flutter_iconpicker/flutter_iconpicker.dart';
I used this as the source pub.dev even in a new project this code
import 'package:flutter/material.dart';
import 'package:flutter_iconpicker/flutter_iconpicker.dart';
void main() {
runApp(
const MaterialApp(
home: HomeScreen(),
),
);
}
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
Icon? _icon;
_pickIcon() async {
IconData? icon = await FlutterIconPicker.showIconPicker(context,
iconPackModes: [IconPack.cupertino]);
_icon = Icon(icon);
setState(() {});
debugPrint('Picked Icon: $icon');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _pickIcon,
child: const Text('Open IconPicker'),
),
const SizedBox(height: 10),
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: _icon ?? Container(),
),
],
),
),
);
}
}
and it shows these errors:
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_iconpicker-3.1.4 1/lib/IconPicker/Packs/Material.dart:1230:25: Error: Member not found: 'class__sharp'.
'class__sharp': Icons.class__sharp,
^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_iconpicker-3.1.4 1/lib/IconPicker/Packs/Material.dart:1231:27: Error: Member not found: 'class__rounded'.
'class__rounded': Icons.class__rounded,
^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_iconpicker-3.1.4 1/lib/IconPicker/Packs/Material.dart:1232:28: Error: Member not found: 'class__outlined'.
'class__outlined': Icons.class__outlined,
^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_iconpicker-3.1.4 1/lib/IconPicker/iconPicker.dart:47:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/binding.dart').
package:flutter/…/widgets/binding.dart:1
WidgetsBinding.instance!.addPostFrameCallback((_) {
^
3
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1156
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 11s
Exception: Gradle task assembleDebug failed with exit code 1
Even if it will not show anything on the emulator the above code is the example of the source that I mentioned above and it was not working and I went according to the instructions that he describes in section (installing) and still not working, Does anyone have a solution to this problem?
CodePudding user response:
Seems the plugin needs to be upgraded!
Solution:If you don't use/need those three icons you can remove/comment those three icons from you local c drive path shown in error.
And add null check operator (!) to the error line shown in error.
Note: Making local changes in plugin will make app run in your end,if you share code they needs to do the above step to run the app
Thanks!!
CodePudding user response:
This is a known issue with flutter_iconpicker
and the new Flutter version 3.0.
There is an open issue with a workaround in the official repository issues