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
Related
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?
I have a Drawer that i share in all my StatefulWidget like this
#override
Widget build(BuildContext context) {
return new Scaffold(
key: _scaffoldKey,
drawer: SharedDrawer()
... //More code
In the Drawer i put a LogOut button that redirect the user to the login page cleaning all the router stack like this.
Navigator.of(context).pop();
Navigator.of(context).pushNamedAndRemoveUntil('/', (Route<dynamic> route) => false);
but when i try to log in again to the app this error appears.
flutter: Looking up a deactivated widget's ancestor is unsafe. At this
point the state of the widget's element tree is no longer stable. To
safely refer to a widget's ancestor in its dispose() method, save a
reference to the ancestor by calling inheritFromWidgetOfExactType() in
the widget's didChangeDependencies() method.
what i'm doing wrong ?
how i can manage the login/out in the app or is something with the navigator stack ?
Regards!
The error "Looking up a deactivated widget's ancestor is unsafe" is usually caused by reusing reference of Widgets that has been disposed previously i.e. during Navigator.of(context).pop();
One way to solve this issue is to keep track the context that you're using on your widgets so it won't reuse previoulsy disposed contexts.
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
I want to prepare some data after user login system. After some google, I implemented a ApplicationListener to listen AuthenticationSuccessEvent:
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
#Component
public class MyApplicationListener implements
ApplicationListener<AuthenticationSuccessEvent> {
#Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
UserDetails userDetails = (UserDetails) event.getAuthentication()
.getPrincipal();
System.out.println("Successed login:" + userDetails.getUsername());
}
}
I updated to Spring 3.0 RELEASE, and Spring Security 3.0.0.RC2. But I can never get called for AuthenticationSuccessEvent:( (I tried other event, such as AuthenticationFailureBadCredentialsEvent, it worked).
I use my own authentication-manager and do nothing about the event:
Do I need to podcast the event by myself?
Thank you.
You don't specify the details of your configuration. You state that you use your own authentication-manager - does this mean you are configuring the ProviderManager explicitly using Spring Bean configuration?
If so, you need to configure the AuthenticationEventPublisher on the ProviderManager, as the default implementation is a null implementation, which doesn't publish events.
The bean declaration for the default implementation is like this:
<bean id="defaultAuthEventPublisher" class="org.springframework.security.authentication.DefaultAuthenticationEventPublisher"/>
You'll then need to map this bean to the appropriate property on the ProviderManager:
If you aren't declaring your own ProviderManager, unfortunately there is not a way to enable this functionality using the security namespace style of configuration. Hope that answers your question!
I'm using Spring-Security 2.0.4, but I think it's pretty the same.
From what that I saw the ProviderManager is the one that publish the event in case of successful authentication.
Few questions that might help:
Do you use the standard ProviderManager (org.springframework.security.providers.ProviderManager) or supply one of your own?
Maybe the #Component doesn't work?, maybe (just for testing) you can try the regular addListener() function.
The best way to understand what happens is to Ito debug Spring security (locate a break point in ProviderManager), I use to do it a lot and find it pretty useful.
Shay
Maybe you want to listen for the InteractiveAuthenticationSuccessEvent. OpenID for example emits that event only. See also SEC-1534.
I have the same problem and I found a few things that might help.
I think that we should include the following listener in web.xml
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
If you wonder if your problem is in the listener detection or the publising you may tray to lauch events yourself.
SecurityContextHolder.getContext().getAuthentication();
AuthenticationSuccessEvent event = new AuthenticationSuccessEvent(
SecurityContextHolder.getContext().getAuthentication());
eventPublisher.publishEvent(event);