How can solve the error in flutter_paystack? - flutter

Type mismatch: inferred type is Activity? but Activity was expected
Type mismatch: inferred type is BinaryMessenger? but BinaryMessenger was expected

I think this might be that the library is not yet optimized to support Flutter 3 which came out recently. Try to communicate with the devs on their github this error and they might be able to fix it

add this to your pubspec.yaml file, this will solve it for now.
flutter_paystack:
git:
url: https://github.com/definitelyme/flutter_paystack.git
ref: a4a33c3dd0a12f46d655a2e63d11e9f20ba82d01

Related

Flutter-> Error: The argument type 'Column' can't be assigned to the parameter type 'Widget?'

I just upgrade my flutter version few days ago. Now i got error in Column widget.
Here is my error.
And here is my pubspec.yaml
HELP ME TO SOLVE THIS.
This error is misleading, just simplify your column as suggested in the comments by stacktrace2234 to see what really is going on.
Did you update it from a non null safety to a null safety dart version?

Dart/Flutter linter rule: the type to index a map should be the key type of map?

For example, I have Map<int, int> m;. Then I can write down m['hello'] without any compile-time error, but of course, cannot find any element at runtime. I hope it will produce an error (or warning) at compile-time or lint time.
This is a big problem in many cases. For example, when I refactor Map<A, int> m into Map<B, int> m, I want to have compile-time errors for all accesses like m[some_var_of_type_A], instead of no compile-time errors and suddenly it explodes at runtime. As another example, the de-serialized JSON is of type Map<String, ...> but the key is actually a int. So it is tempting to do var userId=42; deserializedJson[userId] but only to find errors. Actually need to do deserializedJson[userId.toString()].
You know, dart's type system is so strong (even null safe!), and I really enjoy it since it catchs a LOT of bugs at compile-time. So I hope this problem can also be addressed at compile-time.
Thanks for any suggestions!
There currently is no lint to warn about doing lookups on a Map with arguments of the wrong type. This has been requested in https://github.com/dart-lang/linter/issues/1307.
Also see https://github.com/dart-lang/sdk/issues/37392, which requests a type-checked alternative to Map.operator []. In the meantime, Dart's extension mechanism allows anyone to easily add such an alternative themselves. For example, package:basics provides a type-checked Map.get extension.
NOTE:
The original answer was wrong and has been edited to:
point out the right/better answer
explain why the original answer was wrong
Thank you #jamesdlin for pointing this out.
Better answer
As pointed by #jamesdlin in his answer, the lint rule mentioned in the question has been requested in the flutter Github issues, and not in production yet.
Original Answer (wrong but kind of related to the question)
Why it is wrong:
The question was asking about the lint rule when using an index of Map. The answer however gave the lint rule about initializing a map using the wrong index (By the wrong index, I mean different data type).
Below is the answer:
There is a lint rule for this.
For example, if you define a Map like this ->
final Map<String, String> m = {
1: 'some random value',
};
It shows an error right away and this won't compile. This is the error ->
Error: A value of type 'int' can't be assigned to a variable of type 'String'.
1: 'error because index is of type String but assigned value is of type int',
^
Error: Compilation failed.
See the official docs where this lint rule, map_key_type_not_assignable is defined.
I have tested this in dartpad and vs code. Both IDEs show this error.
There could be some issues in your IDE configuration if you're not seeing this lint error.
As for your question, there is already a lint rule for this as explained above.

Flutter compile error: non-null value must be returned since the return type 'String' doesn't allow null - displayString

My tests are failing to compile and run in a Dart only project that is referenced by my Flutter project. I'm receiving the following error message
Failed to precompile test:test:
../../../../../../../../../.pub-cache/hosted/pub.dartlang.org/analyzer-1.0.0/lib/src/error/best_practices_verifier.dart:1952:14: Error: A non-null value must be returned since the return type 'String' doesn't allow null.
String get displayString {
Any ideas please?
Flutter 2.2.1 (current stable channel)
Tools • Dart 2.13.1
(I've asked the question in Flutter's github here also)
https://github.com/flutter/flutter/issues/83683
There was a component using analyzer version 1.0.0
Upgrading this component to use analyzer version 1.7 or above seemed to fix the problem for me.
go to this file: flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.5.0/lib/src/error/best_practices_verifier.dart:1978:14.
and add below:-
default:
return '';
Please check the function displayString to make sure that it returns non-null string variable. There are some use cases that I guess you might face with
Use "required" if you get the variable from parameters (ex: String displayString(required String var)).
If the variable is optional parameter, then you need to check if it is null or not. Then, you could "return var!;" to let the function knows that you already confirmed the variable content.
If you want to return nullable String, then you should change the function to "String? displayString".

How to debug the Null Safety default value type error on double question mark '??'

I recently run into some strange behavior when using double question mark.
Here is the example code:
void main() {
String strA;
String strB;
print('start');
strB = strA ?? 5; // wrong use of default value type. It should be a String here.
print('end');
}
The program never run to the end and even not throwing out any error message.
Is the behavior expected?
How you're running this code?
When I run it, I get this output:
▶ dart test.dart
start
Unhandled exception:
type 'int' is not a subtype of type 'String'
#0 main (file:///Users/renato/programming/projects/test.dart:6:3)
As I expected.
What Dart version are you using (run dart --version)? Make sure you have an up-to-date version like 2.10.
If you still have issues, you might have a local analysis_options.yaml file which overrides the Dart compiler checks to be more lenient, in which case it might not check the types (I am not sure which option would enable this, but I suppose it's possible).
Check how analysis options work here.
I suggest you always enable "strong mode" by adding this to your analysis options file:
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
By the way, if you want to try the new Dart NNBD (Not-Null-By-Default) experimental feature, you need to use the Dart dev channel releases and run your program with dart --enable-experiment=non-nullable file.dart.
To learn how to enable NNBD, check the null-safety tech preview 2 blog post about it.

How to resolve error "constructors in/after an Optional Chain are not allowed"

I meet a problem when I'm integrating plugin #babel/plugin-proposal-optional-chaining, and it throws error like this:
constructors in/after an Optional Chain are not allowed.
How to resolve this problem? Thanks.