I have a parent SCS View(SingleChildScrollView) and a child SCS View. Inside the child SCS View there is a Data Table, and the Data Table starts at around bottom quarter of the screen.
Now, I want to scroll the parent SCS View when the user scrolls to the top of Data Table inside child SCS View.
This works naturally in web, but does not work in iOS or anroid. I tried using same Scrollcontroller for both parent & child SCS View and played around with ScrollPhysics. But nothing seem to work. Can you please help me with a solution.
Here is the code:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Report'),
),
),
),
);
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final ScrollController scrollController = ScrollController();
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
Text('Some Data', style: TextStyle(fontSize: 30)),
Text('Some Data', style: TextStyle(fontSize: 30)),
Text('Some Data', style: TextStyle(fontSize: 30)),
Text('Some Data', style: TextStyle(fontSize: 30)),
Text('Some Data', style: TextStyle(fontSize: 30)),
Text('Some Data', style: TextStyle(fontSize: 30)),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 400,
),
child: Scrollbar(
controller: scrollController,
child: SingleChildScrollView(
controller: scrollController,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: [
DataColumn(label: Text('Sl. No.')),
DataColumn(label: Text('Resource Name')),
DataColumn(label: Text('Score at 1')),
DataColumn(label: Text('Score at 2')),
DataColumn(label: Text('Final Score')),
],
rows: [
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
DataRow(
cells: [
DataCell(Text('1')),
DataCell(Text('Person 1')),
DataCell(Text('5')),
DataCell(Text('2')),
DataCell(Text('8')),
],
),
],
),
),
),
),
)
],
),
);
}
}
Thank you.