Flutter upgrader, prompt showing only once - flutter

I try to force users to upgrade app each time there is a new version with https://pub.dev/packages/upgrader. It works but only once, when there is a new version. When the dialog is opened and the user closes app. It won't ask again for update. Anyone has solution to that?

the default value for upgrader to remind user to update app is 3 days if you want to change this time you can use durationUntilAlertAgain parameter
upgrader: Upgrader(
durationUntilAlertAgain: const Duration(minutes: 5),
),
for exmaple:
durationUntilAlertAgain: const Duration(minutes: 5),
in the above example if the user close app at 00:00 am and re-open it at 00:03 am the alert message will not appear however if user re-open it at 00:07 am or later the alert message will appear
alternatively you can force user to update the app by adding exit function to ignore or later button here is an example solve your question :
UpgradeAlert(
upgrader: Upgrader(
showLater: false,
onIgnore: () {
SystemNavigator.pop();
throw UnsupportedError('_');
},
),
child: HomePage(),
),

How frequent do you want dialog to pop up? Upgrader widget accepts an attribute durationUntilAlertAgain and its accpetion object of Duration(). You pass whatever duration you want dialog will pop up after that duration.

Related

How to update state when Navigating back to a page Flutter

i am creating a social media like app, when user clicks on post ,it redirects to a commentpage,in commentspage data is coming from a seperate API,so when go back using Navigator.pop(context), the data in home is not updated, if pressed like button,its not reflecting in ui, but updating in Api,
i wrapped Navigator with setstate but its not reflecting,
Use this on navigator push Navigator.push(context).then((value)=>setState((){}); when it pop the screen it will run the setState
Use this sentence to go to the second page so the function will wait second screen to close
bool result = await Navigator.push(context);
if(result){setState((){});}
when u close the second screen use this sentence Navigator.pop(context, true);
so when u comment has been posted successfully, u will back to screen one and complete the function if result boolean is true, else do nothing.

Change the Page to another page in flutter at a specific date and time

So I want my flutter application to navigate the user to a new page called home page at a particular date and time of that date this is my code can I change it to work not after 5 seconds but on Wed,7 Sep at 8:00 am
#override
void initState() {
Timer(
Duration(seconds: 5),
() => Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (BuildContext context)=>GamePage())),
);
super.initState();
Check if the current date is equal to the date (and time if you need time as well) you want and then execute the timer function.
DateTime today=DateTime.now();
if(DateTime(today.year,today.month,today.day)==DateTime(2022,9,7,8,0)){
//Timer function
}
I guess you are looking for is notifications. You can make it work like...
the backend sends a notification on this particular time
if the app is active and receives this notification, you can navigate to the required screen
If the app is inactive, the user will receive the notification and if he opens the app through notification, you can directly navigate them to the required screen.
If he doesn't open the app through notification, you can simply check your required date and time with the current date and time, and navigate accordingly.

Flutter web update url/route base on state

I'm new in flutter and I just want to know if this scenario/feature is possible in flutter/flutter web. I want to update the url/route base on the state of the screen. For example, in 9gag.com, there are buttons for Hot, Trending, and Fresh. Then, if I clicked the Hot button its url will be updated to 9gag.com/hot and also its contents, the same goes for Trending and Fresh buttons. Is this possible in flutter/flutter web? If so, how do I implement this feature?(much better if the implementation uses bloc)
Totally possible and is very easy to achieve just use url_launcher Package on onpressed/ontap
Example: Add this code somewhere like in the beginning of your stateful management or at the end of your code
_launchURL() async {
const url = 'https://flutter.io';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Call it somewhere like this
RaisedButton(
onPressed: _launchURL,
child: new Text('Show Flutter homepage'),
),
),
Now if you have some 9gag/hot button or container whatever you are going with just put that url and when user taps it, it will open that url. If you want to open it inside the app webview that's also possible but slightly different.
If I understood correctly It's pretty straightforward use the default way of navigation and routing.
I'm not sure with your approach like you have mentioned
I want to update the url/route base on the state of the screen
and
Then, if I clicked the Hot button its url will be updated to 9gag.com/hot and also its contents
If I'm not wrong there is a inbuilt feature of navigating to other screens and once you land on the desired screen, you can see the refreshed content. If you want to try material design the code will be like this
//within your stateful or stateless widget
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => YourPage()),
Instead of using a package you can try this inbuilt way of doing the same job. But it's upto you which one you want to use. Checkout the official flutter documentation https://flutter.dev/docs/cookbook/navigation
I hope this approach also helps to answer your question. If so happy to help in your flutter journey, if not share that how did you solved it.

Last Flutter SnackBar is shown again each time I push a new route

I am new with Flutter development, I am developing a simple app that displays SnackBars to inform the user on the progress of the communication with the server.
Everything seems to work correctly but after the snack bars have been displayed, when I Push a new route, the latest snackbar re-appears without me calling it.
Once a SnackBar has been displayed and disappears, is there something that must be done to clean things up and avoid the snackbar from appearing again?
You can use like this,
_scaffoldKey.currentState.removeCurrentSnackBar();**<--this close previous already open snackbar-->**
_scaffoldKey.currentState.showSnackBar( **<--this open new same time-->**
SnackBar(
content: Text('Processing Data'),
),
);
_scaffoldKey ;
Create key
Using key
To hide snackbar :-
Scaffold.of(context).hideCurrentSnackBar();
or if u define global key then :-
_scaffoldKey.currentState.removeCurrentSnackBar();
The issue seemed to be related to the fact thatI was using SnackBars from two different libraries, one of them was ez_flutter the other was fluter material

Creating a Flutter Alert/Dialog Without Context

I currently have a Flutter app which keeps track of the amount of time a user spends on the app with a timer which runs in the background. Users can set limits on the amount of time they spend in the app. Every minute, the timers checks if the user has exceeded their time limit. If so, I want to display a dialog or alert telling the user this.
The problem is that the timer has no way to access the current context and thus no way to create my dialog. Is there a way to get around this?
There is a package that enables you show dialogs with no need BuildContext from business layer. It's called OneContext.
That package also works with page navigation, overlays and other things with no need BuildContext.
Take a look at: https://pub.dev/packages/one_context
Use example:
// example dialog
OneContext().showDialog(
// barrierDismissible: false,
builder: (_) => AlertDialog(
title: new Text("The Title"),
content: new Text("The Body"),
)
);
// example snackBar
OneContext().showSnackBar(
builder: (_) => SnackBar(content: Text('My awesome snackBar!'))
);
You can achieve that by creating a custom Dialog Manager and a locator.
You can read the full tutorial here : https://medium.com/flutter-community/manager-your-flutter-dialogs-with-a-dialog-manager-1e862529523a
There is a package for it called Stacked_services
It provides: NavigationService, DialogService and SnackbarService.