iampawan / VelocityX

A minimalist Flutter framework for rapidly building Flutter apps.

Home Page:https://velocityx.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`addObserver` Method is not null safe

michaelspeed opened this issue · comments

The following bug appears while compilation with null safety

Error: Method 'addObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/Users/michaelspeed/fvm/versions/2.10.4/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.addObserver(this);

To Reproduce
Steps to reproduce the behaviour:
Just start compilation using velocity x in any component

Expected behaviour
To compile

Desktop (please complete the following information):

  • OS: mac OS
  • Browser: Chrome
  • Version: 3.5.1
  • Flutter Version: 2.10.4

I don't think it has anything to do with VelocityX. Looks like some other issue @michaelspeed

Screenshot at May 31 12-21-17
Sorry for the half error output, but it seem to be generated from

velocity_x-3.5.1/lib/src/flutter/common/velocity_ensure_visible.dart:67:29

static WidgetsBinding? get instance => _instance; is nullable by default

Have you tried upgrading the Flutter version @michaelspeed ?

I was using 2.10.4, I will try this with 3.0.1

Yeah let me know if that works otherwise I will push another update with a potential fix

This seems to work on 3.0.1. Closing this, I guess it will be better to mention which version can be used for flutter 2 and flutter 3.

Yeah I didn't know that such issue exists with Flutter 2

I want to work on this issue to support both flutter 2 and flutter 3.

when this will be released?

@

when this will be released?

Fixed in #147. But not merged yet.