2

Back button is not enabled in chrome. So when navigate to next screen then i don't have any option to come back to previous screen. The issue occurs for below cases Launch any flutter web application either directly by

  1. Clicking link or
  2. From IDE like visual studio code,

It's weird that it works when you either press refresh button in chrome after application is launched in browser. Or when application is deployed, copy the link and paste in the tab in browser and press enter.

How to resolve it that back button should be enabled when navigated to next screen on directly launching the app in browser from IDE or pressing the link .

Anyone can check it by creating a new flutter web project and run . I am pasting my sample code for reference

import 'package:back_button_sample/second_screen.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () => Navigator.of(context)
              .push(MaterialPageRoute(builder: (ctx) => SecondScreen())),
          child: Text('Next'),
        ),
      ),
    );
  }
}

Second screen

import 'package:flutter/material.dart';

class SecondScreen extends StatelessWidget {
  const SecondScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text('Second screen'),
    );
  }
}
vivek_ios
  • 173
  • 3
  • 13
  • 1
    I am experiencing the same issue. I thought I had done something wrong but if I open the browser window manually, the back button appears. I am debugging with VS Code – Christian Findlay Jun 24 '22 at 23:18

0 Answers0