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

Add customizable mouse cursor to DataTable #123128

Merged
merged 2 commits into from Mar 24, 2023

Conversation

TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Mar 21, 2023

fixes #123020

Description

  1. Add mouseCursor to the DataColumn for the header cell.
  2. Add mouseCursor MaterialStateProperty to the DataRow for the data row
  3. Add headingCellCursor to customize the cursor in the header cell from DataTableTheme.
  4. Add dataRowCursor to customize the cursor in the data row from DataTableTheme.
code sample
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(useMaterial3: true),
      home: const DataTableExample(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final MaterialStateProperty<MouseCursor?> rowCursor =
        MaterialStateProperty.resolveWith<MouseCursor?>(
      (Set<MaterialState> states) {
        if (states.contains(MaterialState.disabled)) {
          return SystemMouseCursors.forbidden;
        }

        if (states.contains(MaterialState.selected)) {
          return SystemMouseCursors.copy;
        }
        return SystemMouseCursors.grab;
      },
    );

    return Scaffold(
      appBar: AppBar(
        title: const Text('DataTable'),
      ),
      body: DataTable(
        columns: <DataColumn>[
          DataColumn(
            label: const Expanded(
              child: Text(
                'Name',
              ),
            ),
            mouseCursor: MaterialStateProperty.resolveWith(
              (Set<MaterialState> states) {
                if (states.contains(MaterialState.disabled)) {
                  return SystemMouseCursors.forbidden;
                }
                return SystemMouseCursors.grab;
              },
            ),
            onSort: (int columnIndex, bool ascending) {},
          ),
          DataColumn(
            mouseCursor: MaterialStateProperty.resolveWith(
              (Set<MaterialState> states) {
                if (states.contains(MaterialState.disabled)) {
                  return SystemMouseCursors.forbidden;
                }
                return SystemMouseCursors.grab;
              },
            ),
            label: const Expanded(
              child: Text(
                'State',
              ),
            ),
          ),
        ],
        rows: <DataRow>[
          DataRow(
            mouseCursor: rowCursor,
            cells: const <DataCell>[
              DataCell(Text('Row')),
              DataCell(Text('disabled')),
            ],
          ),
          DataRow(
            mouseCursor: rowCursor,
            onSelectChanged: (bool? selected) {},
            cells: const <DataCell>[
              DataCell(Text('Row')),
              DataCell(Text('enabled')),
            ],
          ),
          DataRow(
            mouseCursor: rowCursor,
            selected: true,
            onSelectChanged: (bool? selected) {},
            cells: const <DataCell>[
              DataCell(Text('Row')),
              DataCell(Text('selected')),
            ],
          ),
        ],
      ),
    );
  }
}
Screen.Recording.2023-03-22.at.16.16.59.mov

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 21, 2023
@jpnurmi
Copy link
Member

jpnurmi commented Mar 21, 2023

Hey @TahaTesser, thanks for working on this! Is it intentional that the checkbox in the header doesn't get any mouse cursor assigned? Personally, given that checkbox mouse cursors are themeable, I'd be fine with not assigning a mouse cursor to data row checkboxes either just to keep it consistent.

@TahaTesser
Copy link
Member Author

TahaTesser commented Mar 22, 2023

Hey @TahaTesser, thanks for working on this! Is it intentional that the checkbox in the header doesn't get any mouse cursor assigned? Personally, given that checkbox mouse cursors are themeable, I'd be fine with not assigning a mouse cursor to data row checkboxes either just to keep it consistent.

That makes sense. Just updated the PR to not update the checkboxes cursor and include a test that verifies it.
Also added update video and code sample in the description.

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HansMuller HansMuller merged commit f7fb14e into flutter:master Mar 24, 2023
67 checks passed
@TahaTesser TahaTesser deleted the data_table_cursor branch March 24, 2023 09:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataTable: customizable mouse cursor
3 participants