Flutter和落镖误差:导入“文件包:flutter_iconpicker/flutter_iconpicker. dart”;

tv6aics1  于 2023-03-21  发布在  Flutter
关注(0)|答案(3)|浏览(127)

我正在尝试添加未来(选择图标),因此我使用了此软件包:

import 'package:flutter_iconpicker/flutter_iconpicker.dart';

我用它作为pub.dev的源代码,甚至在一个新项目中也是如此

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(),
            ),
          ],
        ),
      ),
    );
  }
}

它显示了这些错误:

/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

即使它不会在模拟器上显示任何东西,上面的代码是我上面提到的源代码的例子,它不工作,我按照他在第(installing)节中描述的指示去做,仍然不工作,有人能解决这个问题吗?

vngu2lb8

vngu2lb81#

看来plugin需要升级了!
解决方案:如果您不使用/不需要这三个图标,您可以从显示错误的本地c驱动器路径中删除/注解这三个图标。
并将空检查操作符(!)添加到error中显示的错误行。
注意:在插件中进行本地更改将使应用程序在您的终端运行,如果您共享代码,他们需要执行上述步骤来运行应用程序
谢谢!

ftf50wuq

ftf50wuq2#

这是flutter_iconpicker和新Flutter版本3.0的已知问题。
在官方存储库问题中有一个具有解决方法的未决问题。转录如下:
打开YOUR_PC/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_iconpicker-3.1.4+1/lib/IconPicker/Packs/Material.dart文件,搜索并注解包含class_sharp、class_rounded、class_outlined的行,并重建项目。

44u64gxh

44u64gxh3#

我已经提出了一个拉取请求来修复这个包,并删除对这个库使用的不同图标包中不再存在的图标的引用:https://github.com/Ahmadre/FlutterIconPicker/pull/57
同时,您可以使用我的版本的这个库,直到repo所有者合并修复:https://github.com/rasulf/FlutterIconPicker/tree/remove-whatsapp-material-icons-ref
在你的pub spec.yaml中,只需要像这样修改你定义依赖的方式:

flutter_iconpicker:
  git:
    url: https://github.com/rasulf/FlutterIconPicker
    ref: remove-whatsapp-material-icons-ref

相关问题