how to get rect from a stateless widget in flutter - widget

we can get the rect from from a stateful widget by adding global key to it, but
how to get the rect from a stateless widget in flutter? as all the fields in a stateless widget must be final, I can't add global key to it.

Related

Xamarin Forms Google Maps dynamic Api Key [duplicate]

I have a use-case in my android app that users of my application have to give API key so that they can use the map.
but I see that I have to give the API key in the manifest file. which I can't edit at the runtime.
is there any other ways to give the map API key dynamically to the google map (I'm using MapView) or any ways to change the meta-data values dynamically
Unfortunately, this does not seem possible at all.
Google documentation
https://developers.google.com/maps/documentation/android-sdk/get-api-key#add_key strictly talks about the manifest and how to add the key to the local.properties:
Open the local.properties in your project level directory, and then add the following code. Replace YOUR_API_KEY with your API key.
MAPS_API_KEY=YOUR_API_KEY
and then referencing it from the Manifest:
In your AndroidManifest.xml file, go to com.google.android.geo.API_KEY and update the android:value attribute as follows:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
Deprecated and since removed constructor
Apparently, a long time ago there was indeed a way of injecting the key when instantiating the MapView object manually (i.e. not with a layout xml): https://stackoverflow.com/a/11739039
mMapView = new MapView(this, mapApiKey);
However, this constructor was removed since and you cannot give the API key anymore:
https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/MapView?hl=en#public-constructor-summary
MapView(Context context)
MapView(Context context, AttributeSet attrs)
MapView(Context context, AttributeSet attrs, int defStyle)
MapView(Context context, GoogleMapOptions options)

Resolving a dependency while supplying values for downstream dependencies

I've been running into endless problems attempting to use Windsor with Web API and injecting HttpRequestMessage into downstream dependencies of a controller. Since I've tried all the matching answers on Stackoverflow, I'd like to ask the question in a different way:
In Castle Windsor, how can I resolve a component instance while supplying a value for a downstream dependency? That is, the supplied value is required by a component that is required by the component being resolved.
For context, I'm trying to inject HttpRequestMessage so that I can use it to resolve the request context (primarily to resolve an absolute URL).
Edit I'd also like to point out that I don't currently have a dependency on Web Host / System.Web and I'd rather not change that.
A proper approach is to
Create IMyDesiredRouteParameterProvider
Implement it. Get the current request inside it and get the url
Register it and inject it in the desired dependent class via constructor.
I made myself such an implementation and I can say that this way it works fine. You can make Web.Infrastructure assembly and put the implementation there. Or put both the interface and the implementation there if you are going to reference it from another web module.
using System;
using System.Web;
namespace RouteParameterProvider
{
interface IMyRouteParameterProvider
{
string GetRouteParameter();
}
public class ControllerActionMethodRouteParameterProvider : IMyRouteParameterProvider
{
public string GetRouteParameter()
{
string Parameter = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"] as string;
if (string.IsNullOrEmpty(Parameter))
{
throw new InvalidOperationException();
}
return Parameter;
}
}
}
You can get every possible thing that the Request Context contains from :
HttpContext.Current.Request.RequestContext
And it will be better if you rethink your design decision :
I need HttpRequestMessage to be regstered prior to creating each
instance of SomethingController so that it will be available down at
the LinkGenerator layer.
Containers are to be initialized at runtime and then used to resolve.
I need HttpRequestMessage to be regstered prior to creating each
instance of SomethingController so that it will be available down at
the LinkGenerator layer.
It sounds like you want to register an item with the container at runtime, post-startup. In general, this is not a good practice--registration should be a discrete event that happens when the app is fired up, and the container's state should not be changed during runtime.
Dependency Injection is about resolving service components, not runtime state--state is generally passed via methods (method injection). In this case it sounds like your LinkGenerator component needs access to the ambient state of the request.
I'm not that familiar with HttpRequestMessage, but this answer seems to show that it is possible to retreive it from HttpContext.Current. You could make this a method on your LinkGenerator class, or wrap this call in a separate component that gets injected into LinkGenerator (HttpRequestMessageProvider?). The latter would be my preferred method, as it allows LinkGenerator to be more testable.
Given the lack of a clean way of doing this and Web API not providing information as to the hosted endpoint beyond per-request context objects, I ended up injecting the base url from configuration.
Is this library by Mark Seemann the answer? In the description he writes explicitly :
This approach enables the use of Dependency Injection (DI) because the
request can be injected into the services which require it.
Then gives an example :
// Inside an ApiController
var uri = this.Url.GetLink(a=> a.GetById(1337));
By which you can then pass the URL down the road in the service that you have injected in the controller.
UPDATE :
Mark Seemann wrote about the same exact problem here:
"Because HttpRequestMessage provides the context you may need to
compose dependency graphs, the best extensibility point is the
extensibility point which provides an HttpRequestMessage every time a
graph should be composed. This extensibility point is the
IHttpControllerActivator interface:..."
This way you can pass request context information to a component deep in the object graph by getting from the HttpRequestMessage and passing it to the DI container.
Just take a look at the interface of IHttpControllerActivator.
The WEB API framework gets the IHttpControllerActivator through DependencyResolver. You probably already replaced it by your CastleWindsorDependencyResolver. Now you have to implement and register your HttpControllerActivator and register it.
When the WEB API framework gets IHttpControllerActivator from DependencyResolver (your Castle Windsor DR) and calls IHttpControllerActivator.Create() it will pass you the HttpRequestMessage. You can get your info from there and pass it to the your CastleDR before you call Resolve(typeof(MyController)) which will resolve the whole object graph - that means you will have MyHttpContextInfo to inject in your XYZComponent deep in the resolution stack.
This way tou are passing the arguments in the last possible moment but it is still possible. In Castle Windsor I make such passing of arguments though CreationContext.AdditionalArguments["myArgument"];.

Navigation Pattern in WinRT

My doubt is when we navigate from one page to another page in WinRT the Constructor() and On Navigated to() methods are called.
Can we restrict the constructor calling.
As my requirement is i have to attach a new object to the datacontext while navigating again.
You can't create an object without calling its constructor. You can set the DataContext in OnNavigatedTo().

Can the Proxy class be used in AS3 on existing classes?

The AS3 Proxy class extends Object and exposes methods that you can override to handle the addition/removal and getting/setting of properties on the object in a universal fashion.
It appears that existing objects such as MovieClip, Sprite, etc. do not inherit from the Proxy class, so it would seem to preclude the possibility of adding such functionality to existing display object classes.
I've created a layout framework with a base display object class called GUIControl that inherits from MovieClip, and I was hoping to add data-binding functionality to it by overriding the Proxy class's setProperty method, so I could handle property assignments with a single handler to make all properties function as binding sources by default.
Is there some way to utilize the Proxy class's functionality on existing classes, or am I stuck building classes from scratch based on Proxy?
You may create a wrapper class for MovieClip and set property on the wrapper. You should override other functions in Proxy and call the relative functions on MovieClip.
Here is an example
import flash.display.MovieClip;
import flash.utils.Proxy;
import flash.utils.flash_proxy;
public class MovieClipWrapper extends Proxy
{
public function MovieClipWrapper(target:MovieClip)
{
super();
_target = target;
}
private var _target:MovieClip;
override flash_proxy function setProperty(name:*, value:*):void
{
//set data on target movieClip, or call the notify functions
}
}
No, it cannot be used on existing classes. The worst part is that rules out using Proxy on any display list classes. There is no way to alter a property on a display list class and have the Proxy class intercept and handle the setting or getting of such a property value. Proxy is useful only as a base class for new classes (ideally dynamic classes), where you want to intercept and run logic when properties are set/retreived/removed.
Futhermore, Proxy is useless for trying to wrap something like the Dictionary class, since Proxy's interface methods rely on QName and String-type keys exclusively, which makes it impossible to enumerate over, get, or set Dictionary values that use object instances as keys... something Dictionary supports unlike associative arrays or normal Objects.

AS3 Prototypes - are they just static variables?

A reference to the prototype object of a class or function object. The
prototype property is automatically created and attached to any class
or function object that you create. This property is static in that it
is specific to the class or function that you create. For example, if
you create a class, the value of the prototype property is shared by
all instances of the class and is accessible only as a class property.
Instances of your class cannot directly access the prototype property.
A class’s prototype object is a special instance of that class that
provides a mechanism for sharing state across all instances of a
class. At run time, when a property is not found on a class instance,
the delegate, which is the class prototype object, is checked for that
property. If the prototype object does not contain the property, the
process continues with the prototype object’s delegate checking in
consecutively higher levels in the hierarchy until Flash Player or the
Adobe Integrated Runtime finds the property.
Note: In ActionScript 3.0, prototype inheritance is not the primary
mechanism for inheritance. Class inheritance, which drives the
inheritance of fixed properties in class definitions, is the primary
inheritance mechanism in ActionScript 3.0.
So, from this I get the impression that prototypes are just static variables.. am I right?
Not exactly, a function implemented as a prototype is still executed as instance method. In a static function you don't have access to this.
Also it doesn't mean setting a prototype value to something is setting the value for every instance. It's only the fallback value, if an object of that class isn't setting it explicitly.
var o1:Object= {};
var o2:Object= {};
Object.prototype.foo = "foo";
o1.foo = "bar"
trace(o1.foo) // bar
trace(o2.foo) // foo