Required type Context provided android.content.Context in android - android-activity

I am calling a method that takes one argument but when I am passing that argument then it shows an error that the required Type is Context, but provided android.content.Context I don't know that how can I fix that. please help.

Related

The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'.dart

I am getting an error it is saying "The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'.dart"
error on this part Navigator.of(context).pop()
It looks like you've imported by mistake the dart:js module. If so, just remove it:
import 'dart:js'; // <- Remove this import
The dart:js module exports a global context of type JsObject and its type conflicts with the BuildContext type.

Why direct usage of generic value is not possible but same is possible if returned from method in Dart

Why is it assigning a value to a generic field is not possible when assigned directly, but same is possible when using a variable reference or method return value (here, same value is assigned to the variable and method returns the same value)?
class User {}
class Teacher extends User {}
class Student extends User {}
Future<User> getUser() {
return Future.value(Student());
}
void main() {
Future<Future<User>> fut = Future.value(getUser()); // <----- No error
Future<Future<User>> fut2 = Future.value(Future.value(Student())); // <----- Getting error
Future<User> userFut3 = Future.value(Student());
Future<Future<User>> fut3 = Future.value(userFut3); // <----- No error
}
Getting below error when Future.value(Future.value(Student())) assigned directly.
Error: The argument type 'Student' can't be assigned to the parameter type 'FutureOr<Future<User>>?'.
The issue here is that the parameter of Future<T>.value has the type FutureOr<T>. It can be either a future or a value.
Also, Dart type inference works by "pushing down" a context type, then trying to make the expression work at that type, and finally pushing the final static type back up.
If an expression like Future.value(...) has a context type, the missing type argument is always inferred from the context type.
When you write
Future<Future<User>> fut2 = Future.value(Future.value(Student()));
the context type of the outer Future.value, the type we know it should have, is Future<Future<User>>. That makes its argument have context type FutureOr<Future<User>>.
The argument is Future.value(Student()), where we don't yet know anything about Student() because we haven't gotten to it in the type inference yet, we're still working out way down towards it.
A Future<X> can satisfy that FutureOr<Future<User>> in two ways, either by being a Future<User> or by being a Future<Future<User>>.
Type inference then guesses that it's the latter. It's wrong, but it can't see that yet. The way type inference works, it has to use the context type when there is one, but the context type is ambiguous, and it ends up choosing the wrong option.
You are hitting an edge case of the type inference where the context type can be satisfied in two different ways, and the downwards type inference chooses the wrong one. It's a good heuristic that if you have a FutureOr<...> context type, and you see a Future constructor, you want the Future-part of the FutureOr<...>. It breaks down when you have FutureOr<Future<...>>. So, don't do that!
My recommendation, in complete generality, is to never have a Future<Future<anything>> in your program. Not only does it avoid problems like this, but it's also a better model for your code.
A future which eventually completes to something which eventually completes to a value ... just make it eventually complete to that value directly. Waiting for the intermediate future is just needless busywork.
Because in the function you defined the return type and dart knows the return type, but when assigning directly dart does not know Future.value(Student()) has a type of Future<User>. to fix this you have to tell the dart the type of the value, like this: Future.value((Future.value(Student())) as Future<User>);
this way dart will know the type of this value and treat it as a Future<User>.

type 'Future<void>' is not a subtype of type 'Widget'

I have looked for similar answers and tried using their proposed solutions with no success. I am trying to build a dropdown with data from the dynamic. Every time I try to run it, it gives me a
"type 'Future' is not a subtype of type 'Widget'" and I am using Getx framework in flutter
If you had code then it would easy to pinpoint the issue. Basically you are returning nothing from your function that is its return type is Future and calling that function for some parameter that expects to receive a widget. So your function should return some class that extends statelessWidget or statefulWidget.
Hope makes sense.

Where is 'With' method defined. ReactiveUI

I saw here that we can use
(new TestScheduler()).With(sched =>{
// Code run in this block will have both RxApp.MainThreadScheduler
// and RxApp.TaskpoolScheduler assigned to the new TestScheduler.
});
But where is With method defined. I cant find any. Please help.
Microsoft.Reactive.Testing.TestScheduler does not contain a definition for With and no extension method With accepting a first argument of type Microsoft.Reactive.Testing.TestScheduler could be found
This is an extension method defined here and you need nuget package reactiveui-testing to have it available.

DbProviderFactories.GetFactory Method (DbConnection) missing

According to MSDN there is an overload of GetFactory(DbConnection) in .NET 4. However, I can't invoke it - fails at compile time saying:
error BC30518: Overload resolution failed because no accessible 'GetFactory' can be called with these arguments:
'Public Shared Function GetFactory(providerRow As System.Data.DataRow) As System.Data.Common.DbProviderFactory': Value of type 'System.Data.Common.DbConnection' cannot be converted to 'System.Data.DataRow'.
'Public Shared Function GetFactory(providerInvariantName As String) As System.Data.Common.DbProviderFactory': Value of type 'System.Data.Common.DbConnection' cannot be converted to 'String'.
Is there something wrong with my .NET FW or is it a typo in documentation?
You can call the "GetFactory" method using the following solution:
https://msdn.microsoft.com/en-us/library/dd0w4a2z%28v=vs.110%29.aspx
DbProviderFactory factory =
DbProviderFactories.GetFactory(providerName);