I had a Dart trouble, the vscode analyzer stopped without reason.
I reinstall vscode/dart/flutter, then get packages again and nothing happens.
I found this strange non-logic problem
class MyApp extends StatelessWidget {
String get isWhatever:ist => "";
// This widget is the root of your application.
#override
...
}
I discovered I accidentally commited a : instead L, the function name was isWhatever:ist instead isWhateverList. Somebody know why?
Related
I am getting the following error when I deploy a Vaadin 14 web application on Tomcat 9.0.46
Caused by: com.vaadin.flow.server.AmbiguousRouteConfigurationException: Navigation targets must have unique routes, found navigation targets 'xx.SForceFindPaymentView' and 'xx.SForceFindPaymentView' with parameter have the same route.
The class is defined as follows:
#Route(value = "sf-find-payment", layout = MainLayout.class)
#PageTitle("Find Payment")
public class SForceFindPaymentView extends FindPaymentView implements HasUrlParameter<String>, IAAPConnection {
And the parent class is defined as follows:
#PageTitle("Find Payment")
#Route(value = "find-payment", layout = MainLayout.class)
public class FindPaymentView extends VerticalLayout implements HasUrlParameter<String>, IAAPConnection {
The only difference between the parent class and the derived class is the way the parameters are handled in the setParameter() method.
The setParameter method has the following signature
#Override
public void setParameter(final BeforeEvent event, #OptionalParameter final String parameter) {
The odd thing is if I delete the war and redeploy the exact same war file the problem goes away and the application installs successfully.
I tried removing the #OptionalParameter annotation but that made no difference. The error message seems to see two routes for the same class, one with a parameter and one without so I thought if I removed the #OptionalParameter in both the parent and derived class, that might help but it made no difference.
Grateful for any suggestions.
I was trying to debug an issue I was having and I've seen in this answer an advice to set debugPrintScheduleBuildForStacks to true.
I've managed to find the docs for it however, nowhere on the internet I was able to find a guide on how to actually use them.
I've tried setting it as a global variable, a variable inside my widgets as well as changing it directly in the source file (debug.dart) however, I did not manage to see the debug logging as in the answer mentioned above.
Can someone explain, or point me to some docs on how to use it?
Inside build() in main.dart
I have used debugPrintScheduleFrameStacks.
You can replace it with debugPrintScheduleBuildForStacks.
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
debugPrintScheduleFrameStacks = true;
doc: https://pub.dev/documentation/flutter_for_web/latest/widgets/debugPrintScheduleBuildForStacks.html
I'm having a terrible time getting this program to run. I keep getting compiler troubles when I run the code. See specifics below. Anybody understand what's going on here?
My code extract from file TapScreenToo.dart:
import 'profiles.dart';
import 'package:flutter/material.dart';
import 'cards.dart';
class PageTapScreen extends StatefulWidget {
final List<Profile> profileList;
Key key;
PageTapScreen({
this.key,
this.profileList,
}) : super(key: key); // constructor
#override
_PageTapScreenState createState() => new _PageTapScreenState();
}
The profile class in file profiles.dart (no import statement there):
class Profile {
final String ttaKey;
final String imageUrl;
final String displayName;
Profile({
this.ttaKey,
this.imageUrl,
this.displayName,
});
}
my profile list from file demoProfiles.dart:
import 'profiles.dart';
final List<Profile> demoProfiles = [
new Profile(
ttaKey: "0",
imageUrl: 'http://localhost:8080/photo_0.jpg',
displayName: 'abc',
),
new Profile(
ttaKey: "1",
imageUrl: 'http:// ... etc
),
]
And all of this gets called in main.dart
import 'package:flutter/material.dart';
import 'tapScreenToo.dart';
import 'demoProfiles.dart';
class _MyHomePageState extends State<MyHomePage> {
final Key keyOne = PageStorageKey('pageOne');
...
#override
void initState() {
tapScreen = PageTapScreen(
key: keyOne,
profileList: demoProfiles, <--- error points here
);
I'm getting a compiler message at the time of initiation:
compiler message: lib/main.dart:68:20: Error: A value of type 'dart.core::List<#lib1::Profile>' can't be assigned to a variable of type 'dart.core::List<#lib2::Profile>'.
compiler message: Try changing the type of the left hand side, or casting the right hand side to 'dart.core::List<#lib2::Profile>'.
compiler message: profileList: demoProfiles,`
I've tried to cast (List <Profile>) but that seems to be a fail, or I'm just doing it wrong.
Note: when I remark out the error line, and debug step to the failure location, I can see that the values for both keyOne and demoProfiles are exactly as expected. Note, these code snippets are located in different files, linked via import commands.
As I look at the rest of the code, I can see where import 'profiles.dart' gets called multiple times.
I don't understand the error message. I've also studied this posting with a similar error, but I'm just not seeing what's going on with this code, nor how to fix it.
You need to change the imports in the main.dart:
import 'tapScreenToo.dart';
import 'demoProfiles.dart';
Since the main.dart can only have packages: imports which are called absolute imports.
Therefore change the imports to:
import package:mypackage/path/tapScreenToo.dart
import package:mypackage/path/demoProfiles.dart
Check this:
Error: A value of type 'List<#lib1::Data>' can't be assigned to a variable of type 'List<#lib2::Data>
https://github.com/dart-lang/sdk/issues/33076
https://www.dartlang.org/tools/pub/get-started#importing-libraries-from-packages
I've created a small app to add items in list, however when i delete something from list, it gets deleted successfully but ListView.builder doesn't show correct values. i know its something related to keys given to class but i'm pretty new in flutter so don't know how to do that.
Gist: https://gist.github.com/OculusMode/213052325ec725aad3ab92c73599b187
Thanks in advance.!
Add this to constructor of your Widget:
:super(key:new ObjectKey(_data))
Example:
class TodoTile extends StatefulWidget {
String _data;
int _index;
ValueChanged<int> onDelete;
TodoTile(this._data,this._index,{ #required this.onDelete , Key key}):super(key:new ObjectKey(_data));
TodoTileState createState() {return new TodoTileState(_data, _index,this.onDelete);}
}
Not sure if this would cause problems too but I've also changed widget.onDelete to onDelete (passing the function pointer to the state too)
Source:
https://flutter.io/widgets-intro/#keys
I'm trying to obtain the top-level state of my app using a .of()-method, similar to the Scaffold.of() function. This is the (stripped down) code:
class IApp extends StatefulWidget {
#override
IAppState createState() => new IAppState();
static IAppState of(BuildContext context) =>
context.ancestorStateOfType(const TypeMatcher<IAppState>());
}
The app is started using runApp(new IApp)
This Widget creates a HomePage:
#override
Widget build(BuildContext context) {
return new MaterialApp(
// ommitted: some localization and theming details
home: new HomePage(),
);
}
Then, I try to access the State from the HomePage (a StatefulWidget itself):
#override
Widget build(BuildContext context) {
return new Scaffold(
// ommited: some Scaffold properties such as AppBar
// runtimeType not actual goal, but just for demonstration purposes
body: new Text(IApp.of(context).runtimeType.toString()),
);
}
The strange this is, the code works when I place the code for HomePage in the same file as the IApp, but just as an extra class. However, when I place HomePage in a separate file (main.dart and homepage.dart importing each other), the return value of IApp.of(context) is null.
What causes this? And how can I fix it?
TDLR: imports file only using
import 'package:myApp/path/myFile.dart';
Never with
import './myFile.dart';
This is due to how dart resolves imports.
You may have a single source file, but during builds, there is some kind of duplicates.
Let's say you're working on 'myApp'. To import a file, you could do both :
import 'relativePath/myFile.dart'
import 'package:myApp/path2/myFile.dart'
You'd think that they point to the same file right?
But no. One of them will point to the original source. While the other one will point to a temporary file used for the build.
The problem comes when you start to mix both solutions. Because for the compiler, these two files are different. Which means that IApp imported from package:myApp/IApp is not equal to the same IApp imported from relativePath/myApp/IApp
In your case, you inserted in your widget tree an IApp from pakage:path but your IApp.of(context) use IAppState resolved locally.
They both have a different runtimeType. Therefore const TypeMatcher<IAppState>() won't match. And your function will return null.
There's an extremely easy way to test this behavior.
Create a test.dart file containing only
class Test {
}
then in your main.dart add the following imports :
import 'package:myApp/test.dart' as Absolute;
import './test.dart' as Relative;
You can finally test this by doing :
new Relative.Test().runtimeType == new Absolute.Test().runtimeType
Spoiler: the result is false
Now you can use the relative path.
You can verify this, as Remy suggested two years ago:
Relative.Test().runtimeType == Absolute.Test().runtimeType
Spoiler: the result is true