I'am a new coder and try to code a Loginterminal.
I want to make a query to check if the parameter username is the same as the username from the list. However, I get an error message and I don't understand where the problem is.
if (var = user.front().getNutzername()) { }
Error report: The expression must have a boolean type (or be convertible to a boolean type).
Related
In the context of a Flutter 2.0.5 app whose state I'd like to manage with Riverpod, I thought I can declare a StateNotifierProvider like this:
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counterProvider = StateNotifierProvider<CounterStateNotifier>((ref) => CounterStateNotifier());
class CounterStateNotifier extends StateNotifier<int> {
CounterStateNotifier([int count = 0]) : super(count);
void increment() => state++;
}
But Android Studio (and later the Dart compiler as well) complains about the line where I declare the counterProvider variable:
The type 'StateNotifierProvider' is declared with 2 type parameters, but 1 type arguments were given.
Removing the <CounterStateNotifier> type parameter in StateNotifierProvider<CounterStateNotifier> removes the error. However, attempting to read the provider and call its increment method (setting () => context.read(counterProvider).increment() as the onPressed of an ElevatedButton, then pressing the button) gives the following runtime error:
'increment'
method not found
Receiver: 0
Arguments: []
Why is context.read(counterProvider) returning the int state instead of the notifier? And what is the reason behind the type parameter error mentioned in the first part of my question?
I should mention that I'm running my app on the web (with flutter run -d Chrome).
As of Riverpod 0.14.0, State is the default value exposed by StateNotifierProvider.
The syntax for declaring your StateNotifierProvider is now as follows:
final counterProvider = StateNotifierProvider<CounterStateNotifier, int>((ref) => CounterStateNotifier());
Accessing functions now requires adding .notifier (accessing the StateNotifier itself):
context.read(counterProvider.notifier).increment();
And like you've noticed, you now access the state like so:
final count = context.read(counterProvider);
More on the changes here.
You may also use dynamic to accept any type if value for the StateNotifierProvider
final modelProvider =
StateNotifierProvider.autoDispose<ModelClassName, dynamic>(
(ref) => ModelClassName());
As I'm upgrading my application to PHP 7.3, I decided to add return type hinting to my entities methods.
An example would be something like this:
class User {
private $username;
public method getUsername(): string { return $this->username}
}
I use this entity in a form (to create users) where I bind it like so:
$user = new User();
$form->bind($user);
$form->setData($data);
However I get this error which is caused by the hydrator (I'm using the DoctrineObject hydrator)
Return value of Admin\Entity\Auth\User::getUsername() must be of the type string, null returned
#0 ...\vendor\doctrine\doctrine-module\src\DoctrineModule\Stdlib\Hydrator\DoctrineObject.php(220): Admin\Entity\Auth\User->getUsername()
#1 ...\vendor\doctrine\doctrine-module\src\DoctrineModule\Stdlib\Hydrator\DoctrineObject.php(116): DoctrineModule\Stdlib\Hydrator\DoctrineObject->extractByValue(Object(Admin\Entity\Auth\User))
#2 ...\vendor\zendframework\zend-form\src\Fieldset.php(650): DoctrineModule\Stdlib\Hydrator\DoctrineObject->extract(Object(Admin\Entity\Auth\User))
...
From the snippet above it's obvious that it's calling the getUsername method on an "empty" object, which makes it return null and throw the exception.
This is not logically correct as the entity is supposed to have a username so marking it as nullable (?string) is not correct.
Is there any better solution to this? Because making every single method return type nullable seems like a hack that defeats the purpose.
This is my coding for SiteID (Customized Existing Field)
[PXDefault(typeof(Search<PX.SM.RelationGroup.groupName,InnerJoin<PX.SM.Users, On<PX.SM.RelationGroup.groupMask,Equal<PX.SM.Users.groupMask>>,InnerJoin<INSite, On<PX.SM.RelationGroup.groupName,Equal<INSite.siteCD>>>>,Where<PX.SM.Users.pKID, Equal<Current<AccessInfo.userID>>>>),PersistingCheck = PXPersistingCheck.Nothing)]
and when publish the project it got error:
error CS0311: The type 'PX.Data.Where<PX.SM.Users.pKID,PX.Data.Equal<PX.Data.Current<PX.Data.AccessInfo.userID>>>' cannot be used as type parameter 'OrderBy' in the generic type or method 'PX.Data.Search<Field,Where,OrderBy>'. There is no implicit reference conversion from 'PX.Data.Where<PX.SM.Users.pKID,PX.Data.Equal<PX.Data.Current<PX.Data.AccessInfo.userID>>>' to 'PX.Data.IBqlOrderBy'.
error CS0311: The type 'PX.Data.InnerJoin<PX.SM.Users,PX.Data.On<PX.SM.RelationGroup.groupMask,PX.Data.Equal<PX.SM.Users.groupMask>>,PX.Data.InnerJoin<PX.Objects.IN.INSite,PX.Data.On<PX.SM.RelationGroup.groupName,PX.Data.Equal<PX.Objects.IN.INSite.siteCD>>>>' cannot be used as type parameter 'Where' in the generic type or method 'PX.Data.Search<Field,Where,OrderBy>'. There is no implicit reference conversion from 'PX.Data.InnerJoin<PX.SM.Users,PX.Data.On<PX.SM.RelationGroup.groupMask,PX.Data.Equal<PX.SM.Users.groupMask>>,PX.Data.InnerJoin<PX.Objects.IN.INSite,PX.Data.On<PX.SM.RelationGroup.groupName,PX.Data.Equal<PX.Objects.IN.INSite.siteCD>>>>' to 'PX.Data.IBqlWhere'.
enter image description here
It looks like you have wrongly modified the PXDefault attribute.
If you want to set a default value using a BQL, you must be using the Search instead of PXSelect
see the sample below
[PXDefault(typeof(Search<SOOrderType.iNDocType, Where<SOOrderType.orderType, Equal<Current<SOLineSplit.orderType>>>>), PersistingCheck = PXPersistingCheck.Nothing)]
I am calling a method "get_text" on GText.buffer detailed here http://oandrieu.nerim.net/ocaml/lablgtk/doc/GText.buffer.html
let text = textView#buffer#get_text in
However as get_text returns multiple values, when I try to use my variable "text" as a string, for example
textView2#buffer#set_text text;
I get the following error message:
Error: This expression has type
?start:GText.iter ->
?stop:GText.iter -> ?slice:bool -> ?visible:bool -> unit -> string
but an expression was expected of type string
How can I access the string being returned by the method? In general, how can I separate the multiple values returned by a method so I can access and use them individually?
I just looked up your link to lablgtk - it looks like you are missing the ():
let text = textView#buffer#get_text () in ...
The problem with this kind of error is that you are using a (curried) function where a string is required, and the message about the type error sounds kind of "long winded" and not to the point.
So I am attempting to add a repeated field to protobuff. However, whenever I generate the file using make, add_linkage does not take any arguements as if it's not actually able to read in the type that linkage is suppose to take (it's another protobuffer.) What am I doing wrong in the protobuffer file?
package model_velocity.msgs;
import "vector3d.proto";
message ModelVelResponse
{
required string name = 1;
required gazebo.msgs.Vector3d angularVel = 2;
required gazebo.msgs.Vector3d linearVel = 3;
}
message ModelVel_V{
repeated ModelVelResponse linkage = 1;
}
Do I need to do something different? Do I need to call a different function to repeat the message? Any help would be appreciated.
add_linkage() doesn't take any arguments. repeated message types' add_x() method return a pointer to a new, empty instance of the message. You need to do something like ModelVelResponse* resp = my_vodel_vel_v.add_linkage();. Then you can assign to the fields of the returned message as needed.