diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index 50bb90a..4075bc2 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -1,32 +1,12 @@ -name: CI +name: Iconica Standard Component CI Workflow +# Workflow Caller version: 1.0.0 on: - push: - branches: [ master ] pull_request: - branches: - - master - - feature/* - - bugfix/* - - hotfix/* + workflow_dispatch: jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: | - ~/.gradle/wrapper - /opt/hostedtoolcache/flutter - key: ${{ runner.OS }}-flutter-install-cache - - uses: subosito/flutter-action@v2 - with: - channel: 'stable' - - name: Flutter pub get - run: flutter pub get - - name: Flutter format - run: flutter format -o none --set-exit-if-changed . - - name: Flutter analyze - run: flutter analyze + call-global-iconica-workflow: + uses: Iconica-Development/.github/.github/workflows/component-ci.yml@master + secrets: inherit + permissions: write-all \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3d9a204..4e9721f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ migrate_working_dir/ .dart_tool/ .packages build/ +.metadata example/android/ example/ios/ diff --git a/.metadata b/.metadata deleted file mode 100644 index e7011f6..0000000 --- a/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: f1875d570e39de09040c8f79aa13cc56baab8db1 - channel: stable - -project_type: package diff --git a/CHANGELOG.md b/CHANGELOG.md index 35bec5f..32b6cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,3 +10,7 @@ * Added horizontal variant * Adjustable size for the component + +## [1.1.0] - 17 August 2023 + +* Set scrolling to the current time by default if there are no blocks diff --git a/example/.metadata b/example/.metadata index 5651284..d07f2f1 100644 --- a/example/.metadata +++ b/example/.metadata @@ -1,11 +1,11 @@ # This file tracks properties of this Flutter project. # 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: - revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - channel: stable + revision: "efbf63d9c66b9f6ec30e9ad4611189aa80003d31" + channel: "stable" project_type: app @@ -13,11 +13,11 @@ project_type: app migration: platforms: - platform: root - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - - platform: ios - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + create_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31 + base_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31 + - platform: web + create_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31 + base_revision: efbf63d9c66b9f6ec30e9ad4611189aa80003d31 # User provided section diff --git a/example/lib/main.dart b/example/lib/main.dart index 028ab20..d699de3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,7 +3,7 @@ // SPDX-License-Identifier: BSD-3-Clause import 'package:flutter/material.dart'; -import 'package:timetable/timetable.dart'; +import 'package:flutter_timetable/timetable.dart'; void main() { runApp(const MaterialApp(home: TimetableDemo())); @@ -27,8 +27,8 @@ class _TimetableDemoState extends State { child: Container( color: Colors.red, child: const Padding( - padding: const EdgeInsets.all(8.0), - child: const Text( + padding: EdgeInsets.all(8.0), + child: Text( 'Exercise', style: TextStyle(color: Colors.white), ), @@ -42,8 +42,8 @@ class _TimetableDemoState extends State { child: Container( color: Colors.orange, child: const Padding( - padding: const EdgeInsets.all(8.0), - child: const Text( + padding: EdgeInsets.all(8.0), + child: Text( 'Brunch', style: TextStyle(color: Colors.white), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 35b2503..bb1a5bc 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: async - sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.11.0" boolean_selector: dependency: transitive description: @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: characters - sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.17.2" cupertino_icons: dependency: "direct main" description: @@ -66,63 +66,62 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c + sha256: "2118df84ef0c3ca93f96123a616ae8540879991b8b57af2f81b76a7ada49b2a4" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "2.0.2" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" - js: - dependency: transitive + flutter_timetable: + dependency: "direct main" description: - name: js - sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" - url: "https://pub.dev" - source: hosted - version: "0.6.5" + path: ".." + relative: true + source: path + version: "1.1.0" lints: dependency: transitive description: name: lints - sha256: "5cfd6509652ff5e7fe149b6df4859e687fca9048437857cb2e65c8d780f396e3" + sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "2.1.1" matcher: dependency: transitive description: name: matcher - sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" url: "https://pub.dev" source: hosted - version: "0.12.13" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.5.0" meta: dependency: transitive description: name: meta - sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" path: dependency: transitive description: name: path - sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -132,10 +131,10 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: @@ -172,17 +171,10 @@ packages: dependency: transitive description: name: test_api - sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" url: "https://pub.dev" source: hosted - version: "0.4.16" - timetable: - dependency: "direct main" - description: - path: ".." - relative: true - source: path - version: "1.0.0" + version: "0.6.0" vector_math: dependency: transitive description: @@ -191,6 +183,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" sdks: - dart: ">=2.18.0 <3.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=1.17.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 5fc46aa..1d5e058 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,17 +3,17 @@ description: Timetable Widget publish_to: 'none' -version: 1.0.0+1 +version: 1.1.0+2 environment: - sdk: ">=2.17.6 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.2 - timetable: + flutter_timetable: path: ../ dev_dependencies: diff --git a/lib/src/block_service.dart b/lib/src/block_service.dart index d8f6534..543c45e 100644 --- a/lib/src/block_service.dart +++ b/lib/src/block_service.dart @@ -3,7 +3,7 @@ // SPDX-License-Identifier: BSD-3-Clause import 'package:flutter/material.dart'; -import 'package:timetable/src/models/time_block.dart'; +import 'package:flutter_timetable/src/models/time_block.dart'; /// Combine blocks that have the same id and the same time. List combineBlocksWithId(List blocks) { diff --git a/lib/src/timetable.dart b/lib/src/timetable.dart index f7c5eee..124e41a 100644 --- a/lib/src/timetable.dart +++ b/lib/src/timetable.dart @@ -6,11 +6,11 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -import 'package:timetable/src/block_service.dart'; -import 'package:timetable/src/models/table_theme.dart'; -import 'package:timetable/src/models/time_block.dart'; -import 'package:timetable/src/widgets/block.dart'; -import 'package:timetable/src/widgets/table.dart' as table; +import 'package:flutter_timetable/src/block_service.dart'; +import 'package:flutter_timetable/src/models/table_theme.dart'; +import 'package:flutter_timetable/src/models/time_block.dart'; +import 'package:flutter_timetable/src/widgets/block.dart'; +import 'package:flutter_timetable/src/widgets/table.dart' as table; class Timetable extends StatefulWidget { /// [Timetable] widget that displays a timetable with [TimeBlock]s. @@ -22,6 +22,7 @@ class Timetable extends StatefulWidget { this.tableDirection = Axis.vertical, this.timeBlocks = const [], this.size, + this.initialScrollTime, this.scrollController, this.scrollPhysics, this.startHour = 0, @@ -63,6 +64,9 @@ class Timetable extends StatefulWidget { /// The theme of the timetable. 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. final ScrollController? scrollController; @@ -90,6 +94,8 @@ class _TimetableState extends State { widget.scrollController ?? ScrollController(initialScrollOffset: 0); if (widget.timeBlocks.isNotEmpty) { _scrollToFirstBlock(); + } else { + _scrollToInitialTime(); } } @@ -224,32 +230,28 @@ class _TimetableState extends State { ); } - Size _calculateTableStart(Axis axis) { - return Size( - (axis == Axis.horizontal) - ? _calculateTableTextSize().width / 2 - : _calculateTableTextSize().width + - widget.theme.tablePaddingStart + - widget.theme.tableTextOffset, - (axis == Axis.vertical) - ? _calculateTableTextSize().height / 2 - : _calculateTableTextSize().height, - ); - } + Size _calculateTableStart(Axis axis) => Size( + (axis == Axis.horizontal) + ? _calculateTableTextSize().width / 2 + : _calculateTableTextSize().width + + widget.theme.tablePaddingStart + + widget.theme.tableTextOffset, + (axis == Axis.vertical) + ? _calculateTableTextSize().height / 2 + : _calculateTableTextSize().height, + ); - Widget _showBlock(TimeBlock block, {double linePadding = 0}) { - return Block( - blockDirection: widget.tableDirection, - linePadding: linePadding, - start: block.start, - end: block.end, - startHour: widget.startHour, - hourDimension: widget.hourDimension, - blockDimension: widget.blockDimension, - blockColor: widget.blockColor, - child: block.child, - ); - } + Widget _showBlock(TimeBlock block, {double linePadding = 0}) => Block( + blockDirection: widget.tableDirection, + linePadding: linePadding, + start: block.start, + end: block.end, + startHour: widget.startHour, + hourDimension: widget.hourDimension, + blockDimension: widget.blockDimension, + blockColor: widget.blockColor, + child: block.child, + ); void _scrollToFirstBlock() { SchedulerBinding.instance.addPostFrameCallback((_) { @@ -271,19 +273,32 @@ class _TimetableState extends State { }); } - Size _calculateTableTextSize() { - return (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; + void _scrollToInitialTime() { + SchedulerBinding.instance.addPostFrameCallback((_) { + var startingTime = widget.initialScrollTime ?? TimeOfDay.now(); + var initialOffset = + (widget.hourDimension * (widget.endHour - widget.startHour)) * + ((startingTime.hour - widget.startHour) / + (widget.endHour - widget.startHour)) + + _calculateTableTextSize().width / 2; + _scrollController.jumpTo( + initialOffset, + ); + }); } + 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() { var sum = 0.0; if (widget.mergeBlocks || widget.combineBlocks) { diff --git a/lib/src/widgets/table.dart b/lib/src/widgets/table.dart index 8df2a62..46e0c18 100644 --- a/lib/src/widgets/table.dart +++ b/lib/src/widgets/table.dart @@ -3,7 +3,7 @@ // SPDX-License-Identifier: BSD-3-Clause import 'package:flutter/material.dart'; -import 'package:timetable/src/models/table_theme.dart'; +import 'package:flutter_timetable/src/models/table_theme.dart'; class Table extends StatelessWidget { /// The [Table] to draw an overview of timerange with corresponding hour lines diff --git a/pubspec.yaml b/pubspec.yaml index fc523ae..ac95d29 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ -name: timetable +name: flutter_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 environment: - sdk: ">=2.18.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=1.17.0" dependencies: diff --git a/test/block_service_test.dart b/test/block_service_test.dart index 163171e..190bc11 100644 --- a/test/block_service_test.dart +++ b/test/block_service_test.dart @@ -4,8 +4,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:timetable/src/block_service.dart'; -import 'package:timetable/timetable.dart'; +import 'package:flutter_timetable/src/block_service.dart'; +import 'package:flutter_timetable/timetable.dart'; void main() { group('test combineBlocksWithId', () {