Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Back button not working when Navigating to a Page with PlutoGrid on Android #44

Closed
KaushikGupta007 opened this issue Jun 9, 2024 · 4 comments
Labels
bug Something isn't working stale

Comments

@KaushikGupta007
Copy link

Description:

I am experiencing an issue with the PlutoGrid widget in my Flutter application. When I navigate to a page containing PlutoGrid from the home page, phone navigation(back button or swipe back) on Android devices does not work. Only AppBar back arrow works. I would like to request assistance in resolving this issue or understanding if there is a workaround.

Steps to Reproduce:

  1. Create a new Flutter Project.
  2. Add the pluto_grid package to pubspec.yaml.
  3. Create a home page with a text form field and button to navigate to another page containing PlutoGrid.
  4. Run the app on an Android device.
  5. Click on Text Form Field
  6. Navigate from the home page to the page with PlutoGrid by pressing button.
  7. Try to swipe back to the home page using the Android system gesture or use Android back button.

Expected Behavior:

The swipe back gesture or back button should navigate back to the home page.

Actual Behavior:

The swipe back gesture is disabled and does not navigate back to the home page

Code Sample:

import 'package:flutter/material.dart';
import 'package:pluto_grid/pluto_grid.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Enable Back with PlutoGrid',
      initialRoute: '/',
      routes: {
        '/': (context) => const HomePage(),
        '/plutoGridPage': (context) => PlutoGridPage(),
      },
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Home Page'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          TextFormField(
            decoration: const InputDecoration(labelText: "Back Not Working", hintText: "Back Not Working"),
            onChanged: (val){},
          ),
          const SizedBox(height: 20,),
          ElevatedButton(onPressed: (){
            Navigator.pushNamed(context, "/plutoGridPage");
          }, child: const Text("Pluto Grid Page"))
        ],
      ),
    );
  }
}

class PlutoGridPage extends StatelessWidget {

  PlutoGridPage({super.key});

  // Define columns for PlutoGrid
  final List<PlutoColumn> columns = [
    PlutoColumn(
      title: 'Column 1',
      field: 'column1',
      type: PlutoColumnType.text(),
    ),
    PlutoColumn(
      title: 'Column 2',
      field: 'column2',
      type: PlutoColumnType.text(),
    ),
  ];

  // Define rows for PlutoGrid
  final List<PlutoRow> rows = [
    PlutoRow(
      cells: {
        'column1': PlutoCell(value: 'Row 1 Column 1'),
        'column2': PlutoCell(value: 'Row 1 Column 2'),
      },
    ),
    PlutoRow(
      cells: {
        'column1': PlutoCell(value: 'Row 2 Column 1'),
        'column2': PlutoCell(value: 'Row 2 Column 2'),
      },
    ),
  ];

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: const Text('PlutoGrid Page'),
      ),
      body: PlutoGrid(
        mode: PlutoGridMode.selectWithOneTap,
        columns: columns,
        rows: rows,
      ),
    );
  }
}

Explanation

  1. Define Routes:
    In the MaterialApp widget, the routes parameter is used to define the named routes. The initial route (/) is set to the HomePage.

  2. Navigation:
    In the HomePage widget, the button's onPressed callback uses Navigator.pushNamed(context, '/plutoGridPage') to navigate to the PlutoGridPage.

  3. PlutoGridPage:
    This page contains the PlutoGrid.

Video

screen-20240608-231901.mp4

Additional Context:

Please let me know if there is any additional information required or if there is a known workaround for this issue. Thank you for your assistance!

@KaushikGupta007 KaushikGupta007 added the bug Something isn't working label Jun 9, 2024
@Jakuzeisme
Copy link

Yoooo
Please bro did you find a solution to this?

@KaushikGupta007
Copy link
Author

This pull request fixes this issue bosskmk#1070
You can implement it or directly use this repo pluto_grid

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Dec 29, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants