Flutter delete back button on application bar

I am wondering if anyone knows about the way to remove the back button that appears in the appBar in the flutter application when you use Navigator.popNamed to go to another page, the reason why I do not want this summary page to be that logout, and I want users to use the logout button to start the session.

Any help would be great.

Thanks in advance

+4
source share
3 answers

There is no method popNamed. I guess what you meant pushNamed.

"", new Container() leading AppBar.

, , , , , , . pushNamed Navigator.pushReplacementNamed, .

.

import 'package:flutter/material.dart';

class LogoutPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Logout Page"),
      ),
      body: new Center(
        child: new Text('You have been logged out'),
      ),
    );
  }

}
class MyHomePage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Remove Back Button"),
      ),
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.fullscreen_exit),
        onPressed: () {
          Navigator.pushReplacementNamed(context, "/logout");
        },
      ),
    );
  }
}

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      home: new MyHomePage(),
      routes: {
        "/logout": (_) => new LogoutPage(),
      },
    );
  }
}
+9

,

:

  • (:]) , , : AppBar(...,automaticallyImplyLeading: false,...);

  • , - - , , : Navigator.pushReplacementNamed(## your routename here ##);

  • , - - , , : Navigator.pushNamedAndRemoveUntil(## your routename here ##, f(Route<dynamic>)→bool); f - , true , ( );

  • , - EVER - : Navigator.pushNamedAndRemoveUntil(## your routename here ##, (_) => false);

+3

"" AppBar autoImplyLeading false.

appBar: new AppBar(title: new Text("App Bar without Back Button", automaticallyImplyLeading: false,),
+1
source

Source: https://habr.com/ru/post/1680984/


All Articles