首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误:方法'addPostFrameCallback‘不能在'WidgetsBinding?’上调用。因为它可能是空的。

错误:方法'addPostFrameCallback‘不能在'WidgetsBinding?’上调用。因为它可能是空的。
EN

Stack Overflow用户
提问于 2022-06-16 17:09:39
回答 1查看 229关注 0票数 0

我使用了animated_custom_dropdown: 1.2.2包并尝试使用这段代码创建一个带有下拉列表的搜索栏。但我犯了个大错。如何解决这个问题。

/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/animated_custom_dropdown-1.2.2/lib/dropdown_overlay.dart:57:29:错误:不能在'WidgetsBinding?‘上调用方法'addPostFrameCallback’?因为它可能是空的。

  • 'WidgetsBinding‘来自于’package:WidgetsBinding/src/widget/binding.dart‘WidgetsBinding试着用电话?而不是。WidgetsBinding.instance.addPostFrameCallback((_) {^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/animated_custom_dropdown-1.2.2/lib/dropdown_overlay.dart:185:33:错误:没有名称为“拇指视觉”的参数/C:/src/flutter/packages/flutter/lib/src/material/scrollbar_theme.dart:33:9:(^thumbVisibility上下文:找到此候选项,但参数不匹配。const ScrollbarThemeData({ ^ScrollbarThemeData)

失败:生成失败,出现异常。

  • 其中:脚本'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle‘行: 1102
  • 哪里出了问题:任务的执行失败了:app:compileFlutterBuildDebug‘。

进程‘命令’C:\src\flutter\bin\flutter.bat‘以非零出口值1完成

  • 尝试:使用--stacktrace选项运行以获得堆栈跟踪。使用--info或-调试选项运行以获得更多日志输出。用扫描来获得完整的洞察力。
  • https://help.gradle.org获得更多帮助

生成在48 s异常中失败: Gradle任务assembleDebug失败,退出代码1

代码语言:javascript
运行
复制
import 'package:animated_custom_dropdown/custom_dropdown.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';



const _labelStyle = TextStyle(fontWeight: FontWeight.w600);

class FantomSearch extends StatefulWidget {
  const FantomSearch({Key? key}) : super(key: key);

  @override
  State<FantomSearch> createState() => _FantomSearchState();
}

class _FantomSearchState extends State<FantomSearch> {
  final formKey = GlobalKey<FormState>();
  final List<String> list = ['Developer', 'Designer', 'Consultant', 'Student'];
  final jobRoleDropdownCtrl = TextEditingController(),
      jobRoleFormDropdownCtrl = TextEditingController(),
      jobRoleSearchDropdownCtrl = TextEditingController();

  @override
  void dispose() {
    jobRoleDropdownCtrl.dispose();
    jobRoleFormDropdownCtrl.dispose();
    jobRoleSearchDropdownCtrl.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
          statusBarColor: Colors.white,
        ),
        backgroundColor: Colors.white,
        elevation: .25,
        title: const Text(
          'Custom Dropdown Example',
          style: TextStyle(color: Colors.black, fontSize: 18),
        ),
      ),
      body: ListView(
        padding: const EdgeInsets.all(16.0),
        children: [
          const Text('Job Roles Dropdown', style: _labelStyle),
          const SizedBox(height: 8),
          CustomDropdown(
            hintText: 'Select job role',
            items: list,
            controller: jobRoleDropdownCtrl,
            excludeSelected: false,
          ),
          const SizedBox(height: 24),
          const Divider(height: 0),
          const SizedBox(height: 24),

          // dropdown having search field
          const Text('Job Roles Search Dropdown', style: _labelStyle),
          const SizedBox(height: 8),
          CustomDropdown.search(
            hintText: 'Select job role',
            items: list,
            controller: jobRoleSearchDropdownCtrl,
          ),
          const SizedBox(height: 24),
          const Divider(height: 0),
          const SizedBox(height: 24),

          // using form for validation
          Form(
            key: formKey,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const Text(
                  'Job Roles Dropdown with Form validation',
                  style: _labelStyle,
                ),
                const SizedBox(height: 8),
                CustomDropdown(
                  hintText: 'Select job role',
                  items: list,
                  controller: jobRoleFormDropdownCtrl,
                  excludeSelected: false,
                ),
                const SizedBox(height: 16),
                SizedBox(
                  width: double.infinity,
                  child: ElevatedButton(
                    onPressed: () {
                      if (!formKey.currentState!.validate()) {
                        return;
                      }
                    },
                    child: const Text(
                      'Submit',
                      style: TextStyle(fontWeight: FontWeight.w600),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-16 17:20:10

将animated_custom_dropdown版本降至1.2.1。您正在使用的版本被升级到颤振3。

请检查更改日志这里

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72649536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档