Search
 
SCRIPT & CODE EXAMPLE
 

DART

how to override the back button in flutter

import 'dart:async';

import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title}) :super(key: key);

  final String title;

  @override
  State<StatefulWidget> createState() => new _HomePageState();
}

class _HomePageState extends State<HomePage> {

  Future<bool> _onWillPop() async {
    return (await showDialog(
      context: context,
      builder: (context) => new AlertDialog(
        title: new Text('Are you sure?'),
        content: new Text('Do you want to exit an App'),
        actions: <Widget>[
          TextButton(
            onPressed: () => Navigator.of(context).pop(false),
            child: new Text('No'),
          ),
          TextButton(
            onPressed: () => Navigator.of(context).pop(true),
            child: new Text('Yes'),
          ),
        ],
      ),
    )) ?? false;
  }

  @override
  Widget build(BuildContext context) {
    return new WillPopScope(
      onWillPop: _onWillPop,
      child: new Scaffold(
        appBar: new AppBar(
          title: new Text("Home Page"),
        ),
        body: new Center(
          child: new Text("Home Page"),
        ),
      ),
    );
  }
}
Comment

how do you change the back button flutter

appBar: AppBar(
	title: Text('AppBar'),
    leading: IconButton(icon: Icon(Icons.arrow_back)), // appbar leading icon.
   ),
Comment

flutter back button

onPressed: () {
  Navigator.pop(context);
}
Comment

PREVIOUS NEXT
Code Example
Dart :: chip widget flutter 
Dart :: how to launch url in flutter web 
Dart :: convert future<list list in flutter 
Dart :: int to string dart 
Dart :: how to decorate container in flutter 
Dart :: provider flutter pub 
Dart :: Flutter Popup Menu Button Example Tutorial 
Dart :: flutter layout builder 
Dart :: dart char is uppercase 
Dart :: dart custom exception 
Dart :: dart string to hex 
Dart :: dart list remove item 
Dart :: loop over list dart 
Dart :: flutter transform translate 
Dart :: dart null aware operators 
Dart :: flutter single line list 
Dart :: snackbar in flutter 
Dart :: flutter image load 
Dart :: Named parameters dart 
Dart :: spacer in singlechildscrollview 
Dart :: Flutter list of strings to one String 
Dart :: get second to last item in a list dart 
Dart :: dart ASCII to string 
Dart :: flutter mouse tracker error 
Dart :: flutter logo style 
Dart :: the instance member cannot be accessed in an initializer 
Dart :: android studio not detecting new package in flutter 
Dart :: flutter remove item from list 
Dart :: flutter sizedbo 
Dart :: flutter pop to index 1 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =