I am new to flutter and i want to use this code from a youtube tutorial
class _DeviceWithAvailability extends BluetoothDevice {
BluetoothDevice device;
_DeviceAvailability availability;
int? rssi;
_DeviceWithAvailability(this.device, this.availability, [this.rssi]);
}
but it giving an error
The superclass 'BluetoothDevice ' doesn't have a zero argument constructor.
and suggestion
Try declaring a zero argument constructor in 'BluetoothDevice ', or explicitly invoking a different constructor in 'BluetoothDevice '.
I read the documentation but it isn't clear to me.
Please help mo to solve this.
CodePudding user response:
The problem is in your BluetoothDevice device initialization, because the constructor need many parameters that are mandatory, you have two solutions.
1.Initializate this variable with empty parameters like this:
BluetoothDevice device = BluetoothDevice(...);
2.Add late property and before use this var do you need to initialize with correct information, like this:
late BluetoothDevice device;
and then, before use this var you need to pass the correct information like this:
device = BluetoothDevice(...);
CodePudding user response:
Your suggestion means,
A zero-argument constructor is literally a constructor that can be invoked with zero arguments. This includes constructors that take only optional arguments.
Some examples:
SomeClass();//this is zero argument constructor
SomeClass2(String argument1);//this is one argument constructor
SomeClass3(String argument1,String argument2);//this is 2 argument constructor
