You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.2 KiB
Dart
79 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:tangheem/widgets/auto_scroll_view/scroll_id.dart';
|
|
|
|
class AyaScrollViewer extends StatefulWidget {
|
|
final ScrollToId scrollToId;
|
|
final List<ScrollContent> children;
|
|
final Axis scrollDirection;
|
|
|
|
AyaScrollViewer({@required this.children, @required this.scrollToId, this.scrollDirection = Axis.vertical});
|
|
|
|
@override
|
|
_InteractiveScrollViewerState createState() => _InteractiveScrollViewerState();
|
|
}
|
|
|
|
class _InteractiveScrollViewerState extends State<AyaScrollViewer> {
|
|
List<String> _idList = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
setData();
|
|
}
|
|
|
|
void setData() {
|
|
widget.scrollToId.scrollDirection = widget.scrollDirection;
|
|
_idList = [];
|
|
widget.scrollToId.scrollContentsList = [];
|
|
for (ScrollContent scrollContents in widget.children) {
|
|
if (_idList.contains(scrollContents.id)) {
|
|
throw Exception('Do not use the same id');
|
|
} else {
|
|
_idList.add(scrollContents.id);
|
|
}
|
|
widget.scrollToId.scrollContentsList.add(ScrollContentWithKey.fromWithout(scrollContents));
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant AyaScrollViewer oldWidget) {
|
|
if (widget.children != oldWidget.children) {
|
|
setData();
|
|
}
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
scrollDirection: widget.scrollDirection,
|
|
controller: widget.scrollToId.scrollController,
|
|
physics: BouncingScrollPhysics(),
|
|
child: buildContent(),
|
|
);
|
|
}
|
|
|
|
Widget buildContent() {
|
|
if (widget.scrollDirection == Axis.vertical) {
|
|
return Column(
|
|
children: widget.scrollToId.scrollContentsList.map((scrollContents) {
|
|
return buildRepaintBoundary(scrollContents);
|
|
}).toList(),
|
|
);
|
|
} else {
|
|
return Row(
|
|
children: widget.scrollToId.scrollContentsList.map((scrollContents) {
|
|
return buildRepaintBoundary(scrollContents);
|
|
}).toList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
RepaintBoundary buildRepaintBoundary(ScrollContentWithKey scrollContents) {
|
|
return RepaintBoundary(
|
|
key: scrollContents.key,
|
|
child: scrollContents.child,
|
|
);
|
|
}
|
|
}
|