I'm new to Flutter, so I apologize if the question is very basic.
My problem is with the back button... when I press it it sends me to a black page, but when I press the android back button it works fine. Is there a way to make that button the same as the one on the device?
In Android that button is not necessary, but in iOS it is.
My code is:
class FindDevicesScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
bool scanResult = false;
bool connectedResult = false;
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.pop(context, false),
),
title: Text('Find Devices'),
actions: <Widget>[],
),
https://pub.dev/packages/flutter_blue/example (The example code doesn't have that function)
I tried with:
onPressed: () => Navigator.pop(context, false),
onPressed: () { Navigator.pop(context); },
But it does not work. It doesn't go back to the previous page, but to a black page with nothing.
CodePudding user response:
Have you tried using:
class FindDevicesScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
bool scanResult = false;
bool connectedResult = false;
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop(false),
),
title: Text('Find Devices'),
actions: <Widget>[],
),
CodePudding user response:
Well, I'm new to flutter too but I had a similar problem and I solved it by using pushReplacement
Navigator.of(context).pushReplacement(route)
I don't know if this is correct or not but this was my workaround