Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

安卓下出现了以下报错,不知道该如何解决 #41

Closed
wcyttt opened this issue Mar 31, 2021 · 17 comments
Closed

安卓下出现了以下报错,不知道该如何解决 #41

wcyttt opened this issue Mar 31, 2021 · 17 comments

Comments

@wcyttt
Copy link

wcyttt commented Mar 31, 2021

Uploading 441617178782_.pic_hd.jpg…

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

Uploading 441617178782_.pic_hd.jpg…

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

I/flutter ( 3263): The following NoSuchMethodError was thrown while notifying listeners for AnimationController:
I/flutter ( 3263): The method 'toDouble' was called on null.
I/flutter ( 3263): Receiver: null
I/flutter ( 3263): Tried calling: toDouble()
I/flutter ( 3263):
I/flutter ( 3263): When the exception was thrown, this was the stack:
I/flutter ( 3263): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
I/flutter ( 3263): #1 double./ (dart:core-patch/double.dart:52:23)
I/flutter ( 3263): #2 _GZXDropDownMenuState._animationListener (package:gzx_dropdown_menu/src/gzx_dropdown_menu.dart:140:40)
I/flutter ( 3263): #3 AnimationLocalListenersMixin.notifyListeners (package:flutter/src/animation/listener_helpers.dart:136:19)
I/flutter ( 3263): #4 AnimationController._tick (package:flutter/src/animation/animation_controller.dart:797:5)
I/flutter ( 3263): #5 Ticker._tick (package:flutter/src/scheduler/ticker.dart:238:12)
I/flutter ( 3263): #6 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
I/flutter ( 3263): #7 SchedulerBinding.handleBeginFrame. (package:flutter/src/scheduler/binding.dart:1031:11)
I/flutter ( 3263): #8 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
I/flutter ( 3263): #9 SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:1029:17)
I/flutter ( 3263): #10 SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:963:5)
I/flutter ( 3263): #14 _invoke1 (dart:ui/hooks.dart:265:10)
I/flutter ( 3263): #15 _beginFrame (dart:ui/hooks.dart:192:3)
I/flutter ( 3263): (elided 3 frames from dart:async)
I/flutter ( 3263):
I/flutter ( 3263): The AnimationController notifying listeners was:
I/flutter ( 3263): AnimationController#81df6(▶ 0.000)

@GanZhiXiong
Copy link
Owner

你这是运行我的example报错吗?

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

1.这是我调用的地方,controller外部传入

SelectProject(
  dropdownMenuController: _dropdownMenuController,
  projects: _dynamicModel.projects,
)

2.这是我实现的地方

import 'package:flutter/material.dart';
import 'package:gtucloud/components/empty/index.dart';
import 'package:gzx_dropdown_menu/gzx_dropdown_menu.dart';
import 'provider_model.dart';
import 'package:provider/provider.dart';

class SelectProject extends StatefulWidget {
  final GZXDropdownMenuController dropdownMenuController;
  final List projects;
  SelectProject(
      {Key key, @required this.dropdownMenuController, @required this.projects})
      : super(key: key);

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

class _SelectProjectState extends State<SelectProject> {
  // ignore: unused_field
  DynamicModel _dynamicModel;

  @override
  Widget build(BuildContext context) {
    _dynamicModel = context.watch<DynamicModel>();
    List projects = _dynamicModel.projects;
    String projectId = _dynamicModel.projectId;

    if (projects.length == 0) return EmptyWidget(description: "无项目");
    double _dropDownHeight;
    if (40.0 * projects.length > 300) _dropDownHeight = 300.0;

    return Container(
      child: GZXDropDownMenu(
        // controller用于控制menu的显示或隐藏
        controller: widget.dropdownMenuController,
        // 下拉菜单显示或隐藏动画时长
        animationMilliseconds: 300,
        // 下拉菜单,高度自定义,你想显示什么就显示什么,完全由你决定,你只需要在选择后调用widget.dropdownMenuController.hide();即可
        menus: [
          GZXDropdownMenuBuilder(
            dropDownHeight: _dropDownHeight,
            dropDownWidget: _buildConditionListWidget(
              projectId,
              projects,
              (value) {
                _dynamicModel.setSelectedProjectId(value["id"]);
                _dynamicModel
                    .getAuthDynamic(
                  projectId: value["id"],
                  dynamicTypingEnum: "ALL",
                  currentPage: 1,
                  pageSize: 999,
                )
                    .then((value) {
                  widget.dropdownMenuController.hide();
                });
              },
            ),
          ),
        ],
      ),
    );
  }

  _buildConditionListWidget(
    String selectedProjectId, // 选中项目的id
    List items,
    void itemOnTap(sortCondition),
  ) {
    // project name
    Widget title(Map item, String selectedID) {
      bool isChecked = false;
      if (item["id"] == selectedID) isChecked = true;
      return Expanded(
          child: Text(
        item["name"],
        style: TextStyle(
            color: isChecked ? Theme.of(context).primaryColor : Colors.black),
      ));
    }

    // project icon
    Widget icon(Map item, String selectedID) {
      bool isChecked = false;
      if (item["id"] == selectedID) isChecked = true;
      return isChecked
          ? Icon(
              Icons.check,
              color: Theme.of(context).primaryColor,
              size: 16,
            )
          : SizedBox();
    }

    return ListView.separated(
      shrinkWrap: true,
      scrollDirection: Axis.vertical,
      itemCount: items.length,
      // item 的个数
      separatorBuilder: (BuildContext context, int index) =>
          Divider(height: 1.0),
      // 添加分割线
      itemBuilder: (BuildContext context, int index) {
        Map item = items[index];
        return GestureDetector(
          onTap: () => itemOnTap(item),
          child: Container(
            height: 40,
            child: Row(
              children: <Widget>[
                SizedBox(width: 16),
                title(item, selectedProjectId),
                icon(item, selectedProjectId),
                SizedBox(width: 16),
              ],
            ),
          ),
        );
      },
    );
  }
}

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

我看了我传入的值都是有值的,我哪里用错了吗,我只需要一个下拉的菜单栏

@GanZhiXiong
Copy link
Owner

如果我写的example运行没有问题,你先对照我的example检查下。
最近比较忙,有时间我帮你看下。

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

好吧,现在找不到问题,看源码看不出啥,我只调用了GZXDropDownMenu一个Widget

@GanZhiXiong
Copy link
Owner

你搜索下toDouble ,我怀疑你传入的数值有问题

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

我搜不到toDouble,我直接搜索整个项目,我都没用过这个函数

@GanZhiXiong
Copy link
Owner

你用的flutter哪个版本?

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

这个

 AnimationController:
I/flutter ( 3263): The method 'toDouble' was called on null.

应该是你内部实现的吧,我外部没有传值,1.2.4好像

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

ios14.4版本没问题,14.3版本也有这个问题

@GanZhiXiong
Copy link
Owner

你还是先把我example的代码拷贝过去,多试试吧,应该是你的使用方式有问题

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

解决了,是我的问题

double _dropDownHeight;
    if (40.0 * projects.length > 300) _dropDownHeight = 300.0;

这句有问题,是null

@GanZhiXiong
Copy link
Owner

👍,good!

@wcyttt
Copy link
Author

wcyttt commented Mar 31, 2021

大意了啊,反复查值,但是这个数据在我电脑一定会走那个if,所以没看出来

@GanZhiXiong
Copy link
Owner

我一开始也怀疑过你那句代码有问题,只是没有看到报错定位到那行,所以不敢肯定。

给个star吧😂!
有关注才有动力持续更新!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants