这是我的解决方案,没有提前完成分享,会在聊天结束后更新。
import 'package:flutter/material.dart';
void main() {
runApp( MyApp());
}
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final ScrollController _scrollController = ScrollController(keepScrollOffset:
true, initialScrollOffset: 0.0);
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter chat insta'),
),
body: GestureDetector(
onHorizontalDragUpdate:(offset){
_scrollController.animateTo(offset.localPosition.distance
, duration: const Duration(microseconds: 800), curve: Curves.easeInBack);
},
onHorizontalDragEnd: (dragState){
_scrollController.animateTo(_scrollController.initialScrollOffset, duration: const Duration(seconds: 1), curve: Curves.ease);
},
child: ListView(
physics: const NeverScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
controller: _scrollController,
children: [
DataTable(
columns: const [
DataColumn(
label: Text('ID',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold))),
DataColumn(
label: Text('Name',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold))),
DataColumn(
label: Text('Profession',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold))),
DataColumn(
label: Text('',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold))),
DataColumn(
label: Text('TIme',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold))),
],
rows: const [
DataRow(cells: [
DataCell(Text('1')),
DataCell(Text('Stephen')),
DataCell(Text('Actor')),
DataCell(Text('')),
DataCell(Text('1:30 Pm')),
]),
DataRow(cells: [
DataCell(Text('5')),
DataCell(Text('John')),
DataCell(Text('Student')),
DataCell(Text('')),
DataCell(Text('1:30 Pm')),
]),
DataRow(cells: [
DataCell(Text('10')),
DataCell(Text('Harry')),
DataCell(Text('Leader')),
DataCell(Text('')),
DataCell(Text('1:30 Pm')),
]),
DataRow(cells: [
DataCell(Text('15')),
DataCell(Text('Peter')),
DataCell(Text('Scientist')),
DataCell(Text('')),
DataCell(Text('1:30 Pm')),
]),
],
)
],
),
)),
);
}
}