I have a button, and when I press it, a certain card gets deleted after API call. I have to re-route the user back to the same page so that he sees that the card is deleted. The code works just fine when I run the code on real device, but when I do it in the APK, it partially works. Page has 4 tabs and the selected tab has blue color as opposed to white when not selected. i am on tab number 3 that is index number 2, and When re-route happens, eventually i have to come on the same tab. This is the code :
onPressed: () async {
// after Api calls
Get.back();
setState(() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: ((context) =>
OffersScreenPage(
getIndex: 2,
offers: false,
collection: false,
shopoffers: true,
checkoffers: false,
))));
});
}
Get index takes us to tab number 3. Offers + collection + check offers become false ie white in color and shopOffers is true ie it is selected so it is blue in color.
What happens in APK is that the colors is same but the tab that is actually opened is tab number 2 that is index 1. How is this happening?
Related
I have a page with 4 tabs.
Offers ---> Which shows all the avilable offers. Index = 0
Collected Offers ---> Shows all the offers that we have collected. Index = 1
My Offers ---> Offers that I have added. Index = 2
Check Offers ---> Just to check if I have the required coupon. Index = 3
When we collect the offer in Tab 1 , we route to Tab 2 just to show the user that the offer is collected and is in my collection. The selected tab becomes blue and all other tabs becomes white. I do this by passing boolean flags. This is its code
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: ((context) => OffersScreenPage(
getIndex: 1,
offers: false,
collection: true,
shopoffers: false,
checkoffers: false,
))));
This works just fine both when I run it through terminal and in the APK.
My issue is that when I edit my offer in tab 3 that is my created offers (index = 2)I have to refresh the page so I route to the same tab using this code :
setState(() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: ((context) => OffersScreenPage(
getIndex: 2,
offers: false,
collection: false,
shopoffers: true,
checkoffers: false,
))));
});
This way api is called again and my added offer is updated.
The problem that is coming is that this code works only when I run it in terminal. Whats happening in APK is that actual page thats opened is Tab Number 2 with Index 1 that is "my collection tab" and the tab which is blue is "My Created Offers". So its basically on tab number 2 but showing that its on tab 3.
So when I change Tab From Tab 1 -> tab 2 works fine in terminal code and APK but when I do Tab 3 -> Tab 3 it is tab 3-> tab 2. I hope I made myself clear.
How do i remove this issue? Or is there any other way to call my api to refresh the data.
I have a flutter app that connects via bluetooth with a device by pressing on the device name from the list of paired devices. This is the coding :
final BluetoothDevice server;
DataCollectionPage({required this.server});
...............................................................................
child: ListView(
children: devices
.map((_device)=> BluetoothDeviceListEntry(
device: _device,
enabled: true,
onTap: (){
if (kDebugMode) {
print("item");
}
_startDataCollection(context, _device);
},
................................................................................
void _startDataCollection(BuildContext context, BluetoothDevice server){
Navigator.of(context).push(MaterialPageRoute(builder: (context){
return DataCollectionPage(server: server);
}));
}
Then once I navigate to the "DataCollectionPage" page, I perform some actions and data collection methods and at the end I will be in other page named "DataCollectionTimer". In this page a timer will be displayed on the screen for few seconds then at the end of this timer a Dialog will show to give some message and then finally Once I press the button close on this dialog, I want to go back to DataCollectionPage. So If I try to use
MaterialPageRoute( builder: (context) => DataCollectionPage(), ),
It will give an error because parameter 'server' is required which I obtained from the list of paired devices that was in a different class.
Is there a way to go back to DataCollectionPage from the current one without going all the way back to the page where the list of paired devices is there.
Thank you in advance
You need to make the server field optional and then use popUntil
final BluetoothDevice? server;
DataCollectionPage({this.server});
I am fairly new to state management in Flutter, and I have an application where the user will be interacting with dialogs, and a dialog may have a button to open another dialog which can result in the following:
https://i.stack.imgur.com/VBSzr.png
As shown, multiple issues arise when more than one is opened at once -- most notably the previous dialog is still visible in the background. So when a user opens a new dialog, is there any method where I can hide the dialog behind it, and when the frontmost dialog closes, show the previous one which is hidden? Thanks in advance.
Use Navigator.pop(context); method to close the dialog on your button's onPressed before opening the second dialog.
And then while closing your second dialog you can reopen your previous dialog.
Example:
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Hello World"),
content: Text("This is content"),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context); //Close your current dialog
//TODO:open your second dialog
},
child: Text("Open"))
],
);
});
I would first try to re-think the logic for opening multiple dialogs at the same time.
Maybe there is a quick workaround for that, but if you keep adding more and more dialogs, then it would become a mess.
Since showDialog<T> function returns Future<T?>, you could potentially use await and wait until the first dialog is closed and then open the second one and so on:
bool canContinue = await showDialog<bool>(
context: context,
builder: (context) => YourWidget(),
);
Alternatively, you could pop by using Navigator but as said, this will be visible to the user that something weird is going on (pushing and popping dialogs programatically).
I have two screens:
home_page_screen with listed items (each item has an icon 'favourite' which adds to favourites),
favourites_screen showing the list with clicked favourites items in home_page_screen. I created the favourite_screen with constructor where I am passing the clicked favourites items. When I add the item to favourites in the home_page_screen, the app navigates me to favourite_screen and showing another favourite item.
My question is: How to simply navigate from my home_page_screen to favourites_screen (for example by clicking the icon placed in the NavigationBottomBar without passing any data, just to navigate me there?
Navigator.push(
context,
MaterialPageRoute(
builder: (ctx) {
return favourites_screen();
},
),
);
);
In my project I move from the current page (2) to the previous one (1) an updated a List, through the constructor, with the back button in the appBar
onPressed: () => Navigator.pushReplacement (
context,
new MaterialPageRoute (
builder: (context) => new PagesListPage (
pagesList: list Pages,
)),
)
The data is updated correctly on the previous page
but Flutter rightly 'duplicates' the previous page (1) in the stack, that is:
on page 1 - tap on button to go to page 2 ---> I see page 2
on page 2 - tap on button back in appBar (navigator.pushReplacement) ---> I see page 1
on page 1 - tap on button back in appBar ---> I see again page 1
How can I eliminate the double occurrence of page 1 in the stack?
Or alternatives to update the List on page 1 from page 2.
I'm starting out with Flutter, and I've also tried with Provider, but if I understand correctly it can only update a 'value', I couldn't get it to update a 'List'!
Thanks for any valuable suggestions
On page 1 navigator:
buttonPressPage1() async {
var updatedData = await Navigator.pushReplacement(
context, new MaterialPageRoute(builder: (context) => page1));
setState(() {
oldData = updatedData;
});
}
On page 2 navigator:
buttonPressPage2() {
Navigator.of(context).pop(updatedData);
}
Using await to you can update the data.