我有一个父 SCS 视图(SingleChildScrollView)和一个子 SCS 视图。在子 SCS 视图中有一个数据表,数据表从屏幕底部四分之一左右开始。
现在,当用户滚动到子 SCS 视图内的数据表顶部时,我想滚动父 SCS 视图。
这在 web 中很自然,但在 iOS 或 anroid 中不起作用。我尝试对父和子 SCS 视图使用相同的 Scrollcontroller,并使用 ScrollPhysics。但似乎没有任何效果。你能帮我解决一下吗。
这是代码:
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')),
],
),
],
),
),
),
),
)
],
),
);
}
}
谢谢你。