1 argument required when initalizing another class in my class - function

I want to acces a function from another class. A solution would be to initalize the second class in the class I want to access. Like this:
class Calendarsub extends State<Calendar> with SingleTickerProviderStateMixin{
final TableCalendar tableCalendar;
Calendarsub(this.tableCalendar);
When I do this I can acces the functions but the app is not running because the Stateful Widget says: "1 required Argument expected but 0 found."
class Calendar extends StatefulWidget {
#override
State<StatefulWidget> createState() {
return Calendarsub(); // In this bracket must be the argument
// But I don't know which one
}
}

You constructor needs 1 argument - TableCalendar
So, you have to initialize it with this value:
TableCalendar tableCalendar = TableCalendar(); //or somethimg like that
Calendarsub calendar = Calendarsub(tableCalendar);
or make this parameter optional:
class Calendarsub extends State<Calendar> with SingleTickerProviderStateMixin{
TableCalendar tableCalendar;
Calendarsub({this.tableCalendar});
in second case creating will be like:
Calendarsub calendar = Calendarsub(tableCalendar: TableCalendar());

It sounds like you have two classes using the same name
Calendar, a subclass of StatefulWidget, which takes a parameter
Calendar, a State, which doesn't take any parameter
This confuses the compiler. You need to rename so that there's no name conflict anymore.

Related

Problems with authentication with Laravel 5

I am trying to login a user with laravel 5.
Here is my controller
public function postLogin(LoginRequest $request){
$remember = ($request->has('remember'))? true : false;
$auth = Auth::attempt([
'email'=>$request->email,
'password'=>$request->password,
'active'=>true
],$remember);
if($auth){
return redirect()->intended('/home');
}
else{
return redirect()->route('login')->with('fail','user not identified');
}
}
When i enter wrong credentials, everything works fine, but when i enter the right one, i got this error message:
ErrorException in EloquentUserProvider.php line 110:
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Models\User given, called in C:\xampp\htdocs\Projects\Pedagogia\Admin.pedagogia\vendor\laravel\framework\src\Illuminate\Auth\Guard.php on line 390 and defined
I don't see where i did wrong
Argument 1 passed
to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be
an instance of Illuminate\Contracts\Auth\Authenticatable, instance of
App\Models\User given.
The validateCredentials() method of the Illuminate\Auth\EloquentUserProvider class expects an instance of Illuminate\Contracts\Auth\Authenticable, but you are passing it an instance of App\Models\User. To put it simply, your user model needs to implement the Illuminate\Contracts\Auth\Authenticable interface to work with Laravels authentication scaffolding.
Your App\Models\User model should look like this:
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticable as AuthenticableTrait;
class User extends \Eloquent implements Authenticatable
{
}
#Gaetan you are getting this not found error, because you are using the
use Illuminate\Contracts\Auth\Authenticable instead using use Illuminate\Contracts\Auth\Authenticatable;
you user model should be like that:
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
class User extends Model implements Authenticatable
{
// your code here
}
change Authenticable with Authenticatable.

as3 assign another class to an existing class varriable?

I want to apply a new class to the same var name.
My code:
public var One:Word;
//later called
One = new Word();
// later changed
One = new redWord();
How do I change the var "One" from the class name "Word" to the new class name "redWord"?
You can use class wildcards if you want to be able to assign variables of multiple types to a var:
public var One:*;
Alternatively if both of your classes extend the same class you can use that as the base class for your var:
public class Words{
...
}
public class Poem extends Words{
...
}
public class Prose extends Words{
...
}
public var Soliloquy:Words;
By convention, variable names use lower case and class names use upper case. I would recommend changing One to one and redWord to RedWord.
To be able to assign to One instances of both Word and redWord, it must be declared of a type that is compatible with both. A possibility would be Object, but that may be too generic. Check if there is a common superclass to Word and redWord, and make One of that type.
The more specific your type is, the more errors you will discover at compile time, and the less nasty surprises you will be likely to find at runtime.

How do I register multiple services with a specific interface in Castle Windsor

I have the following registration:
container.Register(AllTypes.FromAssemblyContaining<ITabViewModel>().BasedOn<ITabViewModel>());
Two classes:
public class StructureDecorationViewModel : NotificationObject, ITabViewModel
{
...
}
public abstract class NotificationObject : INotifyPropertyChanged
{
...
}
And two resolvers:
serviceProvider.ResolveAll<System.ComponentModel.INotifyPropertyChanged>()
serviceProvider.ResolveAll<ITabViewModel>()
Both of these Resolvers gives the StructureDecorationViewModel, how can I filter the registration so that I only register the ITabViewModel and not the INotifyPropertyChange?
To register against just one interface you would normally use FirstInterface:
AllTypes
.FromAssemblyContaining<ITabViewModel>()
.BasedOn<ITabViewModel>()
.WithService
.FirstInterface();
However in this case you would end up with your service registered against INotifyPropertyChanged which is not what you want as it picks the first interface from the base class (Have a look at the ServiceDescriptor class to see what other registrations are available).
What you need is the Select method that allows you to define the type or types you want to register the service against:
AllTypes
.FromAssemblyContaining<ITabViewModel>()
.BasedOn<ITabViewModel>()
.WithService
.Select(typeof(ITabViewModel));
However if you want to keep things more generic someone has written an extension method that looks at the service being registered and picks out the first interface on the derived class (http://www.hightech.ir/SeeSharp/windsor-registration-service-interface):
public static BasedOnDescriptor FirstInterfaceOnClass(this ServiceDescriptor serviceDescriptor)
{
return serviceDescriptor.Select((t, bt) =>
{
var baseInterfaces = t.BaseType.GetInterfaces();
var interfaces = t.GetInterfaces().Except(baseInterfaces);
return interfaces.Count() != 0 ? new[] {interfaces.First()} : null;
});
}
Which allows you to do this:
AllTypes
.FromAssemblyContaining<ITabViewModel>()
.BasedOn<ITabViewModel>()
.WithService
.FirstInterfaceOnClass();

Refer to a Spark view component in code

I'm building a mobile AIR app using Flash Builder 4.5. The initial view in my views package is TestHomeView.mxml. I want to refer to it in one of my .as classes elsewhere in the app, and I'm not sure how to do that.
Theoretically I should be able to add an "id" attribute to TestHomeView.mxml, but FB gives me an error: "id is not allowed on the root tag of a component". The root tag is s:view.
The reason I need to do this is that within another class I make various calculations and then need to pass an array of values to a component in my view class. So in SomeOtherActionScriptClass.as I first assemble the array, myArray, and then in that class I want to do this:
myViewComponent.viewArray = myArray;
If I'm going to do that, I also need to import the view class into the .as class, which strikes me as weird. So is there a simple way to do what I want, or do I have to dispatch a custom event which contains the array, and listen for it in the view class?
EDIT - Based on the below MVC suggestion I did the following in model:
[Bindable]
public class Model
{
private static var myModel:Model;//doesn't let me name it 'model' because
//I have a package named 'model'
public var myArray:Array; //its value set later in model code
public function Model()
{
if ( Model.myModel != null ){
throw new Error( "Only one Model instance should be instantiated" );
}
}
// singleton: always returns the one existing static instance to itself
public static function getInstance() : Model {
if ( myModel == null ){
myModel = new Model();
}
return myModel;
}
Then in the view code I have:
[Bindable] //do I actually need this?
private var myModel:Model = Model.getInstance();
var viewArray = new Array();
viewArray = myModel.myArray;
But it is coming back null. It isn't null when I put a breakpoint in the Model class, but when I try to access it from the view class, it's null. The model itself isn't null, but that variable is.
What am I doing wrong?
Thanks.
First, if you are trying to make a singleton in AS3 you should first create a class, within the same class file as Model, that is used to ensure you can only create the class once.
Add this class at the bottom of the Model class file (outside of the Model class):
internal class SingletonEnforcer{}
Then create the Model constructor like this:
public function Model(enforcer:SingletonEnforcer){ Init(); } // if init code is needed
public static function get Instance():Model
{
if (!myModel){
myModel = new Model(new SingletonEnforcer());
}
return myModel;
}
Now you don't have to throw an exception for creating a second instance because it isn't possible.
I'm not sure about your first question of referencing your app's main mxml, but if you were asking how to call the app that is running (like WindowedApplication in AIR) then you would call it like this:
// my WindowedApplication file = MyApp.mxml
MyApp(this.parentApplication)
That will return the app's instance.
Once you've set up the Singleton like I have it above you should be able to access your array like:
Model.Instance.myArray;
I hope this helps!
Follow the MVC pattern.
Create Model class (make it Bindable) with a property viewArray. Bind to this property from your View. And in any other class just change viewArray property of the model. The binding event will be fired and this property will also be changed in your View. To make your Model "visible" from any point, you can make it a Singleton.

AS3 - extend a function?

I have an Entity class with a destroy() function.
I also have an Enemy class that extends Entity, and I want to add some lines to the destroy() function.
Is there a way to extend functions in ActionScript 3, or is copy and paste the way to go? Thanks.
You need to mark the method with the override keyword, and from there use the same namespace (public, protected, etc) and name that make up the method you want to override in the class you're extending.
The method must also have the same return type and accept the same arguments
Sample override:
override public function destroy():void
{
// add more code
super.destroy();
}
If you exclude the line which reads super.destroy(), the function within the base class will not be run, and only your new code will be used instead.