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

PageStorage compatibility #155

Open
jpnurmi opened this issue Dec 1, 2022 · 1 comment
Open

PageStorage compatibility #155

jpnurmi opened this issue Dec 1, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jpnurmi
Copy link

jpnurmi commented Dec 1, 2022

Would it be possible to pass keepScrollOffset: false for the internal "synced" ScrollControllers to avoid conflicts with PageStorage when saving and restoring scrolling positions?

Here's a dummy example to illustrate the issue. Tap a table row and "go back" to navigate away and back. The table should restore its scrolling positions.

keep-scroll-offset.webm
import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      initialRoute: '/table',
      routes: {
        '/table': (_) => const TablePage(),
        '/other': (_) => const OtherPage(),
      },
    ),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () => Navigator.of(context).pushReplacementNamed('/table'),
          child: const Text('Go back'),
        ),
      ),
    );
  }
}

final restorationBucket = PageStorageBucket();

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageStorage(
        bucket: restorationBucket,
        child: DataTable2(
          key: const PageStorageKey('example'),
          columnSpacing: 12,
          horizontalMargin: 12,
          minWidth: 600,
          columns: const [
            DataColumn2(
              label: Text('Column A'),
              size: ColumnSize.L,
            ),
            DataColumn(
              label: Text('Column B'),
            ),
            DataColumn(
              label: Text('Column C'),
            ),
            DataColumn(
              label: Text('Column D'),
            ),
            DataColumn(
              label: Text('Column NUMBERS'),
              numeric: true,
            ),
          ],
          rows: List<DataRow>.generate(
            100,
            (index) => DataRow2(
              cells: [
                DataCell(Text('A' * (10 - index % 10))),
                DataCell(Text('B' * (10 - (index + 5) % 10))),
                DataCell(Text('C' * (15 - (index + 5) % 10))),
                DataCell(Text('D' * (15 - (index + 10) % 10))),
                DataCell(Text(((index + 0.1) * 25.4).toString()))
              ],
              onTap: () => Navigator.pushReplacementNamed(context, '/other'),
            ),
          ),
        ),
      ),
    );
  }
}
@maxim-saplin
Copy link
Owner

Changing that field is not a problem, though I'm not sure of side effects of such a change, that would require thorough testing. If you can submit a PR, add some sample test reproducing the case and add widget tests - I'm happy to review and merge it

@maxim-saplin maxim-saplin added enhancement New feature or request help wanted Extra attention is needed labels Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants