In my app i have three screens login , verifyotp , generatepass. I know how to move from one page to other page eg: Navigator.pushNamed(context, "/theNameOfThePage");.
I have a flow in which i move from login->verifyotp->generatepass my question is now how can i move from generatepass to login page and clearing all the stack.
I am an android developer so in android we have intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);.
How can i achieve same result in flutter!
Full clean of Navigator's history and navigate to new route:
void _logout() {
Navigator.pushNamedAndRemoveUntil(context, "/newRouteName", (r) => false);
}
Use Navigator.popUntil.
void _logout() {
Navigator.popUntil(context, ModalRoute.withName('/login'));
}
To add to Paul Iluhin's answer above, if you want to pass arguments to the new page, just add the arguments after (r) => false. Here is an example.
Navigator.pushNamedAndRemoveUntil(context, "/newRouteName", (r) => false, arguments: {
"arg_1": firstArgument,
"arg_2": secondArgument
});
As others have already mentioned, Navigator.pushNamedAndRemoveUntil is the way to go, but in case if anyone is wondering how to do that using the component type (instead of a string route path), this is how you do it.
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (_)
=> LoginPage()), (route) => false);
I personally prefer using the type name because I change my route path multiple times during the initial development until I reach a stable route name pattern and when I do that, I don't want to do a mass search/replace.
Related
For my project i use User Plugin and Translate Plugin.
I've added custom new fields to the user and now I want to translate them.
I think I know why it does not work. But find no solution.
Somebody to have idea?
if i add to $model->translatable default fields like 'email', works fine.
i added boot function to my custom plugin with this code
\RainLab\User\Models\User::extend(function ($model) {
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
$model->translatable = ['about', 'preview_text'];
});
Hmm,
There is one problem. when you try to add it directly $model->translatable, It seems its treating it like attribute of model.
Try this $model->addDynamicProperty(variable_name, value);
\RainLab\User\Models\User::extend(function ($model) {
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
$model->addDynamicProperty('translatable', ['about', 'preview_text']);
// like this ^
});
It should treat it as local variable and it should work.
If any doubts please comment.
Revision [ Final solution ] - solution for : it works for existing fields when we are adding new fields this is not working.
Problem: With translation mechanism is that it listens the backend.form.extendFieldsBefore event for form and then register fields for translation. When we try to register new fields in form using extendFormFields extension, It happens afterward so new added fields are not visible to translation listener. so they are kind of skipped as translation field registration process already been done.
Solution: So for solution we can just add our field before translation registartion happens. luckily translate plugin has lowest -1 priority for listening this event backend.form.extendFieldsBefore so we can register our fields before It so we are good now and our fields can be added before it can process fields for translation.
Code
\Event::listen('backend.form.extendFieldsBefore', function($widget) {
// You should always check to see if you're extending correct model
if (!$widget->model instanceof \RainLab\User\Models\User) {
return;
}
// we will merge current fields with fields we want to add
// we used shorthand + plus operator for this
$widget->tabs['fields'] = $widget->tabs['fields'] + Config::get('rms.secis::user_fields');
// here Config::get('rms.secis::user_fields') is just returning field array
// Fo ref. Ex:
// return [
// 'gender' => [
// 'label' => 'Gender',
// 'tab' => 'Security Island',
// 'type' => 'radio',
// 'options' => [
// 'male' => 'Male',
// 'female' => 'Female'
// ],
// 'span' => 'auto'
// ],
// ];
});
Note: we are adding fields to tab so we are using $widget->tabs['fields'] to add fields to the tabs. If you want to add normal fields or secondary tab fields you can use $widget->fields and $widget->secondaryTabs['fields] respectively.
Yes now translator can see our fields and its processed, It should able to show translation UI in frontend-ui as well.
if any doubts please comment.
#hardik-satasiya
yes, no more errors on frontend, but new problem is, that no translate functions on fields.
Maybe to add jQuery Script to Controller?
Integration without JQuery and October Framework files:
https://octobercms.com/plugin/rainlab-translate
end of documentation
I have a ListView Builder in the first Page, which receives content(items) from the Second Page. When I hit submit button in Second Page, I use:
Navigator.of(context).pop
Which takes me back to First Screen.
The problem is that it is not updating the item created in the list unless i restart the app.
I have tried:
1) Calling an instance of First Page and using:
firstPageinstance.setState((){});
2) I have also tried to call a function from the First Page class, which invokes setState:
firstPageinstance.funtionWhichCallsetStateinFirstageClass();
But none of this works. The list is updated only when I Restart the App.
P.S. The list items are saved and called from an SQLite database. Also, Let me know if you need more details.
When navigating to your SecondPage await the result like this:
bool isUpdated = await Navigator.push(context, MaterialPageRoute(builder: (context) => SecondPage()),)
if(isUpdated) // do your list update logic here
When going back to FirstPage(tap on submit button), send the expected value such as:
Navigator.pop(context, true);
Helpful read: https://flutter.dev/docs/cookbook/navigation/returning-data
1. Binding Lists
I wonder how I could bind a ObservableCollection to a Radiogroup:
new Section(){
new RootElement("Mandanten", new RadioGroup("mandanten", 2)) {
new Section(){
new RadioElement("Kupus", "mandanten"),
new RadioElement("Kajmak", "mandanten")
}
}
}
as you see here I'm creating 2 Items/Elements manually but I miss something like an "ItemsSource".
If its not possible, what recommendation would you give me? To use witch Control (to bind Lists)?
2. CommandBinding
As I see theres no "button" in MonoTouch.Dialog. So I saw that we'll use "StringElement".
I tried it, but after tapping on the "button" nothing happened:
new StringElement("Login").Bind(this, "SelectedCommand LoginCommand")
I'm not sure whats wrong, maybe I need to use here the new "variant", like that:
new EntryElement ("User", "Loginuser", ViewModel.User).Bind(target, v => v.Value, t => t.User),
But I'm not sure how to build that similiar code to bind a command for a particular "stringelement" (in that case - a button with the ontap event)..
Any help appreciated!
1. Binding lists
An example of binding dynamic ObservableCollection lists is in https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/ThirdView.cs - it uses some custom elements from https://github.com/slodge/MvvmCross-Tutorials/tree/master/DialogExamples/DialogExamples.Touch/BindableElements - which was based on the sample from https://github.com/asednev/MvvmCross.AlexeysExtensions
Because of the way Radio lists are internally implemented, I don't know if the same ObservableCollection binding approach would work for radio lists - someone would need to prototype and experiment to work this out. However, a simple fixed radio list is shown in https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/FirstView.cs
2. CommandBinding
See an example in: https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/Views/FirstView.cs
new Section("Action")
{
new StringElement("Second").Bind(bindings, element => element.SelectedCommand, vm => vm.GoSecondCommand),
new StringElement("Bindable Elements").Bind(bindings, element => element.SelectedCommand, vm => vm.BindableElementsCommand)
},
I am using the pure Razor style definition for a Kendo Menu:
#using Kendo.Mvc.UI
#(Html.Kendo().Menu()
.Name("main-menu")
.Items(items1 =>
{
items1.Add().Text("Home").Url(#Url.Action("Index", "Home"));
items1.Add().Text("Movements").Items(subs =>
{
subs.Add().Text("Import Data").Action("Import", "VehicleMovementBatch");
subs.Add().Text("View Movements");
});
items1.Add().Text("Presences");
items1.Add().Text("Billing");
items1.Add().Text("Config").Items(items2 =>
{
items2.Add().Text("Pricing").Action("Index", "PriceRule");
items2.Add().Text("Users");
});
items1.Add().Text("Control");
})
)
I can find absolutely bloody nothing anywhere on all the internets, that even hints how to do do this properly. The closest I have is defining the DataSource in JavaScript object notation, with separators, and assigning it to the grid oj the client side at run time. This is definitely a good example of a case where can only pray to all the gods that the API isn't as superlatively inadequate as the documentation.
This is all you need to do. Figured it out on my own because I couldn't find an answer anywhere on the web.
items1.Add().Text("<hr/>").Encoded(false).Enabled(false);
The < hr / > thing didn't work for me in kendo 2014.1.528
This does:
children.Add().Text("<div class='k-separator'></div>").Encoded(false).Enabled(false);
So an example would be:
items.Add().Text("Menu X").ImageUrl(Url.Content("~/Content/img/menux_16E.png"))
.Items(children =>
{
children.Add().Text("Item 1").ImageUrl(Url.Content("~/Content/img/item1_16E.png"));
children.Add().Text("<div class='k-separator'></div>").Encoded(false).Enabled(false);
children.Add().Text("Item 3").ImageUrl(Url.Content("~/Content/img/item3_16E.png"));
});
To help anyone coming across this issue in the future, you can add a separator directly with the following:
items.Add().Separator(true);
This works since at least v2013.2.918, since that is what I am using.
Justin
I have v2016.3.914 and items.Add().Separator(true); creates an unwanted horizontal scrollbar on an RTL page.
I solved it using this:
inner.Add().Separator(true).HtmlAttributes(new { style = "width: 99%;" });
Mobile display modes in ASP.NET MVC 4 stop serving the correct views after about an hour of uptime, despite browser overrides correctly detecting an overridden mobile device.
Recycling the application pool temporarily solves the problem.
The new browser override feature correctly allows mobile devices to view the desktop version of a site, and vice-versa. But after about an hour of uptime, the mobile views are no longer rendered for a mobile device; only the default desktop Razor templates are rendered. The only fix is to recycle the application pool.
Strangely, the browser override cookie continues to function. A master _Layout.cshtml template correctly shows "mobile" or "desktop" text depending on the value of ViewContext.HttpContext.GetOverriddenBrowser().IsMobileDevice, but the wrong views are still being rendered. This leads me to believe the problem lies with the DisplayModes.
The action in question is not being cached:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
I am using 51Degrees for mobile detection, but I don't think this should affect the overridden mobile detection. Is this a bug in DisplayModes feature for ASP.NET MVC 4 Beta & Developer Preview, or am I doing something else wrong?
Here is my DisplayModes setup in Application_Start:
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone")
{
ContextCondition = context =>
context.GetOverriddenBrowser().IsMobileDevice
&& (context.Request.UserAgent.IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0
|| context.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0
|| !context.Request.Browser.IsMobileDevice)
});
/* Looks complicated, but renders Home.iPhone.cshtml if the overriding browser is
mobile or if the "real" browser is on an iPhone or Android. This falls through
to the next instance Home.Mobile.cshtml for more basic phones like BlackBerry.
*/
DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("Mobile")
{
ContextCondition = context =>
context.GetOverriddenBrowser().IsMobileDevice
});
This is a known issue in MVC 4 (Codeplex: #280: Multiple DisplayModes - Caching error, will show wrong View). This will be fixed in the next version of MVC.
In the meantime you can install a workaround package available here: http://nuget.org/packages/Microsoft.AspNet.Mvc.FixedDisplayModes.
For most applications simply installing this package should resolve the issue.
For some applications that customize the collection of registered view engines, you should make sure that you reference Microsoft.Web.Mvc.FixedRazorViewEngine or Microsoft.Web.Mvc.FixedWebFormViewEngine, instead of the default view engine implementations.
I had a similar issue and it turned out to be a bug when mixing webforms based desktop views with razor based mobile views.
See http://aspnetwebstack.codeplex.com/workitem/276 for more info
Possibly a bug in ASP.NET MVC 4 related to caching of views, see:
http://forums.asp.net/p/1824033/5066368.aspx/1?Re+MVC+4+RC+Mobile+View+Cache+bug+
I can't speak for this particular stack (I'm still in MVC2) but check your output caching setup (either in your controllers or views - and in your web.config in your app and at the machine level). I've seen it work initially for the first few users and then a desktop browser comes in right around the time ASP decides to cache, then everyone gets the same view. We've avoided output caching as a result, hoping this would get addressed later.
If you want all mobile devices to use the same mobile layout you can use
DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("Mobile")
{
ContextCondition = context =>
context.GetOverriddenBrowser().IsMobileDevice
});
And of course you need to make a view in the shared layout folder named _Layout.Mobile.cshtml
If you want to have a separate layout for each type of device or browser you need to do this;
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Android")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
("Android", StringComparison.OrdinalIgnoreCase) >= 0)
});
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
});
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile")
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
("IEMobile", StringComparison.OrdinalIgnoreCase) >= 0)
});
And of course you need to make a view in the shared layout folder for each named
_Layout.Android.cshtml
_Layout.iPhone.cshtml
_Layout.Mobile.cshtml
Can you not just do this?
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// Code removed for clarity.
// Cache never expires. You must restart application pool
// when you add/delete a view. A non-expiring cache can lead to
// heavy server memory load.
ViewEngines.Engines.OfType<RazorViewEngine>().First().ViewLocationCache =
new DefaultViewLocationCache(Cache.NoSlidingExpiration);
// Add or Replace RazorViewEngine with WebFormViewEngine
// if you are using the Web Forms View Engine.
}
So guys here is the answer to all of your worries..... :)
To avoid the problem, you can instruct ASP.NET to vary the cache entry according to whether the visitor is using a mobile device. Add a VaryByCustom parameter to your page’s OutputCache declaration as follows:
<%# OutputCache VaryByParam="*" Duration="60" VaryByCustom="isMobileDevice" %>
Next, define isMobileDevice as a custom cache parameter by adding the following method override to your Global.asax.cs file:
public override string GetVaryByCustomString(HttpContext context, string custom)
{
if (string.Equals(custom, "isMobileDevice", StringComparison.OrdinalIgnoreCase))
return context.Request.Browser.IsMobileDevice.ToString();
return base.GetVaryByCustomString(context, custom);
}
This will ensure that mobile visitors to the page don’t receive output previously put into the cache by a desktop visitor.
please see this white paper published by microsoft. :)
http://www.asp.net/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application
Thanks and Keep coding.....