how to use ref.refresh(provider) in global using flutter_riverpod - flutter-riverpod

i am using flutter_riverpod plugin
usually i am using ref.refresh(provider) within the stful widget
but How could i use it out of stful widget
examply
// here in global how could i use it ?
stfl{.....}

Related

Using InjectorFactory for routerProviders or routerProvidersHash can be automated?

I'm bootstrap angular with runApp and the namend Parameter "createInjector" to define the routerStrategy "routerProviders" or "routerProvidersHash".
Is there any way to automate this definition like i wish to do this in my first line? For local development i wish to use "routerProvidersHash" and for live environment is wanna use the "routerProvider".
const List<Provider<Object>> routerStrategy = Environment.isLive() ? routerProviders : routerProvidersHash;
#GenerateInjector([
routerStrategy,
ClassProvider(Client, useClass: BrowserClient),
])
final InjectorFactory injector = self.injector$Injector;
void main() {
runApp(ng.AppComponentNgFactory, createInjector: injector);
}
The problem is, that this value need to be a const, but then i can not create the constant like this.
I have no idea to make this more flexible :(
It is const very much on purpose as if it is dynamic like you suggest then it can't be optimized.
What I think you can do is have two injectors one for devel, and one for prod and decide which one to use when you call runApp.

Flutter debugging: Setting debug boolean flags

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

Can I assign a reference to a constructor in Dart?

My use case is in constructing a WidgetApp in flutter:
new WidgetsApp(
pageRouteBuilder: <Contructor for MaterialPageRoute here>,
...
);
Instead of referencing the constructor, I'm just wrapping it in a function:
PageRoute pageRouteBuilder(RouteSettings settings, WidgetBuilder builder) {
return MaterialPageRoute(settings: settings, builder: builder);
}
And then referencing that function later:
new WidgetsApp(
pageRouteBuilder: pageRoutebuilder,
...
);
It used to be possible at some point in the history of Dart (like spread operator).
It is currently not possible though, but the feature may come back at some point.
In the meantime, you can use refactoring options for them to generate some of the boilerplate.
Constructor tear-off are not supported in Dart (https://github.com/dart-lang/sdk/issues/10659)
But even if it was supported, your code cannot really use it. MaterialPageRoute takes settings and builder as named parameters but PageRouteFactory takes 2 positionals parameters. So it wouldn't match.
You can write it like:
new WidgetsApp(
pageRouteBuilder: (settings, builder) => MaterialPageRoute(settings: settings, builder: builder),
);
The automatic inference, allows you to omit the type in the parameter of the closure.

Using modal from semantic ui

I am planing to use semantic ui modal has anyone any idea, how to interoperate with dart?
Use the js package to interoperate. First, add the package as a dependency. Then, wrap the JavaScript that you want to use from Dart. Here's an example allowing you to use jQuery's $(...).addClass(...) in Dart:
#JS()
library jquery;
import 'package:js/js.dart';
// Calls invoke JavaScript `JSON.stringify(obj)`.
#JS("\$")
external ElementSet $(String selector);
#JS()
class ElementSet {
external addClass(String className);
}
If you import this file, you can now do:
$('#output').addClass("red");
That example is, of course, quite useless — Dart already allows you to modify HTML classes with better readability and flexibility (e.g. querySelector('#output').classes.add("red")).
But in your case, it starts to make sense. You would implement modal() and go from there.
(I would give you an example of how to implement modal, but I wasn't able to install semantic ui on my workstation for 10+ minutes and then I gave up. So I used the jQuery.addClass example instead.)
It's not that easy. There are two or three pub packages available but they are outdated and incomplete.
I did it this way in Dart 2 (AngularDart 5):
import 'dart:js';
// somewhere in the component:
context
.callMethod(r'$', [modalSelector])
.callMethod('modal', [new JsObject.jsify({
'onApprove': new JsFunction.withThis((element){
// do something on approve
})
})])
.callMethod('modal', ['show']);
This Dart code is equivalent to this Javascript code:
$(modalSelector).modal({
'onApprove': function(element){
// do something on approve
})
.modal('show');
As you may see, you have to call the jQuery framework through the JS module.

Inject bridge-code in JavaFX WebView before page-load?

I want to load some content or page in a JavaFX WebView and offer a Bridge object to Java so the content of the page can do calls into java.
The basic concept of how to do this is described here: https://blogs.oracle.com/javafx/entry/communicating_between_javascript_and_javafx
Now my question is: When is a good time inject the bridge-object into the WebView so it is available as soon as possible.
One option would be after page load as described here: https://stackoverflow.com/a/17612361/1520422
But is there a way to inject this sooner (before the page content itself is initialized), so the bridge-object is available DURING page-load (and not only after page-load)?
Since no one has answered, I'll tell you how I'm doing it, although it is ugly. This provides the ability for the page to function normally in non-Java environments but receive a Java object in Java environments.
I start by providing an onStatusChanged handler to the WebEngine. It listens for a magic value for window.status. If the magic value is received, the handler installs the Java object. (In my case, it's more complex, because I have some more complex orchestration: I'm executing a script that provides a client-side API for the page and then sets another magic value on window.status to cause the Java object to be sent to an initialization method of the client-side API).
Then in my target page, I have the following code in the first script in the page:
window.status = "MY-MAGIC-VALUE";
window.status = "";
This code is essentially a no-op in a "normal" browser but triggers the initialization when running in the custom JavaFX embedding.
In Java 8, you can trigger event changing from SCHEDULED to RUNNING to inject objects at this time. The objects will present in WebEngine before JavaScript running. Java 7, I see the state machine quite differs in operating, no solution given for Java 7.
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>(){
public void changed(ObservableValue<? extends State> ov,
State oldState,
State newState)
{
// System.out.println("old: "+oldState+", new: "+newState);
if(newState == State.RUNNING &&
oldState == State.SCHEDULED){
JSObject window = (JSObject)webEngine.executeScript("window");
window.setMember("foutput", foutput);
}
}
});

Resources