mirror of
https://github.com/Iconica-Development/flutter_timetable.git
synced 2025-05-18 19:43:43 +02:00
feat: scroll to currentTime when no items
This commit is contained in:
parent
ae8d135eb4
commit
289f1ea25a
6 changed files with 68 additions and 49 deletions
|
@ -10,3 +10,7 @@
|
||||||
|
|
||||||
* Added horizontal variant
|
* Added horizontal variant
|
||||||
* Adjustable size for the component
|
* Adjustable size for the component
|
||||||
|
|
||||||
|
## [1.1.0] - 17 August 2023
|
||||||
|
|
||||||
|
* Set scrolling to the current time by default if there are no blocks
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# This file tracks properties of this Flutter project.
|
# This file tracks properties of this Flutter project.
|
||||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||||
#
|
#
|
||||||
# This file should be version controlled.
|
# This file should be version controlled and should not be manually edited.
|
||||||
|
|
||||||
version:
|
version:
|
||||||
revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
revision: "efbf63d9c66b9f6ec30e9ad4611189aa80003d31"
|
||||||
channel: stable
|
channel: "stable"
|
||||||
|
|
||||||
project_type: app
|
project_type: app
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@ project_type: app
|
||||||
migration:
|
migration:
|
||||||
platforms:
|
platforms:
|
||||||
- platform: root
|
- platform: root
|
||||||
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
create_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31
|
||||||
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
base_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31
|
||||||
- platform: ios
|
- platform: web
|
||||||
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
create_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31
|
||||||
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
base_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31
|
||||||
|
|
||||||
# User provided section
|
# User provided section
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ packages:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "1.0.0"
|
version: "1.1.0"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -3,10 +3,10 @@ description: Timetable Widget
|
||||||
|
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 1.0.0+1
|
version: 1.1.0+2
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.17.6 <3.0.0"
|
sdk: ">=3.0.0 <4.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|
|
@ -22,6 +22,7 @@ class Timetable extends StatefulWidget {
|
||||||
this.tableDirection = Axis.vertical,
|
this.tableDirection = Axis.vertical,
|
||||||
this.timeBlocks = const [],
|
this.timeBlocks = const [],
|
||||||
this.size,
|
this.size,
|
||||||
|
this.initialScrollTime,
|
||||||
this.scrollController,
|
this.scrollController,
|
||||||
this.scrollPhysics,
|
this.scrollPhysics,
|
||||||
this.startHour = 0,
|
this.startHour = 0,
|
||||||
|
@ -63,6 +64,9 @@ class Timetable extends StatefulWidget {
|
||||||
/// The theme of the timetable.
|
/// The theme of the timetable.
|
||||||
final TableTheme theme;
|
final TableTheme theme;
|
||||||
|
|
||||||
|
/// The initial time to scroll to if there are no timeblocks. If nothing is provided it will scroll to the current time or to the first block if there is one.
|
||||||
|
final TimeOfDay? initialScrollTime;
|
||||||
|
|
||||||
/// The scroll controller to control the scrolling of the timetable.
|
/// The scroll controller to control the scrolling of the timetable.
|
||||||
final ScrollController? scrollController;
|
final ScrollController? scrollController;
|
||||||
|
|
||||||
|
@ -90,6 +94,8 @@ class _TimetableState extends State<Timetable> {
|
||||||
widget.scrollController ?? ScrollController(initialScrollOffset: 0);
|
widget.scrollController ?? ScrollController(initialScrollOffset: 0);
|
||||||
if (widget.timeBlocks.isNotEmpty) {
|
if (widget.timeBlocks.isNotEmpty) {
|
||||||
_scrollToFirstBlock();
|
_scrollToFirstBlock();
|
||||||
|
} else {
|
||||||
|
_scrollToInitialTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,32 +230,28 @@ class _TimetableState extends State<Timetable> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Size _calculateTableStart(Axis axis) {
|
Size _calculateTableStart(Axis axis) => Size(
|
||||||
return Size(
|
(axis == Axis.horizontal)
|
||||||
(axis == Axis.horizontal)
|
? _calculateTableTextSize().width / 2
|
||||||
? _calculateTableTextSize().width / 2
|
: _calculateTableTextSize().width +
|
||||||
: _calculateTableTextSize().width +
|
widget.theme.tablePaddingStart +
|
||||||
widget.theme.tablePaddingStart +
|
widget.theme.tableTextOffset,
|
||||||
widget.theme.tableTextOffset,
|
(axis == Axis.vertical)
|
||||||
(axis == Axis.vertical)
|
? _calculateTableTextSize().height / 2
|
||||||
? _calculateTableTextSize().height / 2
|
: _calculateTableTextSize().height,
|
||||||
: _calculateTableTextSize().height,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _showBlock(TimeBlock block, {double linePadding = 0}) {
|
Widget _showBlock(TimeBlock block, {double linePadding = 0}) => Block(
|
||||||
return Block(
|
blockDirection: widget.tableDirection,
|
||||||
blockDirection: widget.tableDirection,
|
linePadding: linePadding,
|
||||||
linePadding: linePadding,
|
start: block.start,
|
||||||
start: block.start,
|
end: block.end,
|
||||||
end: block.end,
|
startHour: widget.startHour,
|
||||||
startHour: widget.startHour,
|
hourDimension: widget.hourDimension,
|
||||||
hourDimension: widget.hourDimension,
|
blockDimension: widget.blockDimension,
|
||||||
blockDimension: widget.blockDimension,
|
blockColor: widget.blockColor,
|
||||||
blockColor: widget.blockColor,
|
child: block.child,
|
||||||
child: block.child,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _scrollToFirstBlock() {
|
void _scrollToFirstBlock() {
|
||||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||||
|
@ -271,19 +273,32 @@ class _TimetableState extends State<Timetable> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Size _calculateTableTextSize() {
|
void _scrollToInitialTime() {
|
||||||
return (TextPainter(
|
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||||
text: TextSpan(
|
var startingTime = widget.initialScrollTime ?? TimeOfDay.now();
|
||||||
text: '22:22',
|
var initialOffset =
|
||||||
style: widget.theme.timeStyle ?? Theme.of(context).textTheme.bodyLarge,
|
(widget.hourDimension * (widget.endHour - widget.startHour)) *
|
||||||
),
|
((startingTime.hour - widget.startHour) /
|
||||||
maxLines: 1,
|
(widget.endHour - widget.startHour)) +
|
||||||
textScaleFactor: MediaQuery.of(context).textScaleFactor,
|
_calculateTableTextSize().width / 2;
|
||||||
textDirection: TextDirection.ltr,
|
_scrollController.jumpTo(
|
||||||
)..layout())
|
initialOffset,
|
||||||
.size;
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Size _calculateTableTextSize() => (TextPainter(
|
||||||
|
text: TextSpan(
|
||||||
|
text: '22:22',
|
||||||
|
style:
|
||||||
|
widget.theme.timeStyle ?? Theme.of(context).textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
textScaleFactor: MediaQuery.of(context).textScaleFactor,
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
)..layout())
|
||||||
|
.size;
|
||||||
|
|
||||||
double calculateTableHeight() {
|
double calculateTableHeight() {
|
||||||
var sum = 0.0;
|
var sum = 0.0;
|
||||||
if (widget.mergeBlocks || widget.combineBlocks) {
|
if (widget.mergeBlocks || widget.combineBlocks) {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
name: timetable
|
name: timetable
|
||||||
description: Flutter package to create a Timetable Widget that display blocks of widgets inside a timetable.
|
description: Flutter package to create a Timetable Widget that display blocks of widgets inside a timetable.
|
||||||
version: 1.0.0
|
version: 1.1.0
|
||||||
repository: https://github.com/Iconica-Development/timetable
|
repository: https://github.com/Iconica-Development/timetable
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.18.0 <3.0.0"
|
sdk: ">=3.0.0 <4.0.0"
|
||||||
flutter: ">=1.17.0"
|
flutter: ">=1.17.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in a new issue