Giter Club home page Giter Club logo

Comments (3)

bosskmk avatar bosskmk commented on July 21, 2024

Thank you for using my package.

I made an example for the Focus problem below.

If the problem is solved or not, please leave a comment.

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

import '../dummy_data/development.dart';

/// How to handle the focus of PlutoGrid and other Focus like Dialog or Modal.
///
/// 1. Wrap the PlutoGrid to FocusScope.
///
/// ```dart
/// child: FocusScope(
///   canRequestFocus: _canGridFocus,
///   child: PlutoGrid(
///     columns: dummyData.columns,
///     rows: dummyData.rows,
///     onChanged: (PlutoOnChangedEvent event) {
///       print(event);
///     },
///   ),
/// ),
/// ```
///
/// 2. When opening a dialog or modal, change the canRequestFocus value
///    passed to the FocusScope of PlutoGrid to false.
///
/// ```dart
/// void setGridFocus(bool flag) {
///   if (flag != _canGridFocus) {
///     setState(() {
///       _canGridFocus = flag;
///     });
///   }
/// }
///
/// floatingActionButton: FloatingActionButton.extended(
///   onPressed: () {
///     setGridFocus(false);
///
///     Future<void> futureModal = showModalBottomSheet<void>(
///      ...
///     );
///      ...
///    },
/// ),
/// ```
///
/// 3. When the open dialog or modal is closed,
///    change the canRequestFocus value passed to the FocusScope of PlutoGrid
///    to true.
///
/// ```dart
/// Future<void> futureModal = showModalBottomSheet<void>(
///   ...
/// );
///
/// futureModal.then((_) {
///   setGridFocus(true);
/// });
/// ```
class HandlingFocusScreen extends StatefulWidget {
  static const routeName = 'handling-focus';

  @override
  _HandlingFocusScreenState createState() => _HandlingFocusScreenState();
}

class _HandlingFocusScreenState extends State<HandlingFocusScreen> {
  final dummyData = DummyData(10, 100);

  bool _canGridFocus = true;

  void setGridFocus(bool flag) {
    if (flag != _canGridFocus) {
      setState(() {
        _canGridFocus = flag;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('PlutoGrid - Handling focus'),),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () {
          setGridFocus(false);

          Future<void> futureModal = showModalBottomSheet<void>(
            context: context,
            builder: (BuildContext context) {
              return Container(
                height: 200,
                color: Colors.white,
                child: Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      const Text('Modal BottomSheet'),
                      TextField(),
                      RaisedButton(
                        child: const Text('Close BottomSheet'),
                        onPressed: () {
                          Navigator.pop(context);
                        },
                      )
                    ],
                  ),
                ),
              );
            },
          );

          futureModal.then((_) {
            setGridFocus(true);
          });
        },
        label: Text('PlutoGrid'),
        icon: Icon(Icons.thumb_up),
        backgroundColor: Colors.pink,
      ),
      body: Container(
        padding: const EdgeInsets.all(30),
        child: FocusScope(
          canRequestFocus: _canGridFocus,
          child: PlutoGrid(
            columns: dummyData.columns,
            rows: dummyData.rows,
            onChanged: (PlutoOnChangedEvent event) {
              print(event);
            },
          ),
        ),
      ),
    );
  }
}

from pluto_grid.

jrheisler avatar jrheisler commented on July 21, 2024

That solved it, thank you!!!

from pluto_grid.

jrheisler avatar jrheisler commented on July 21, 2024

I had no idea you could do that.

from pluto_grid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.