From e848779ee033d1b5e1224e594b543f1c898ffc4e Mon Sep 17 00:00:00 2001 From: Lucas Tonussi Date: Mon, 22 Nov 2021 17:44:31 -0300 Subject: [PATCH 1/8] added factory receiving a widget --- lib/widgets/story_view.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index c83f0e12..0854061f 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -161,6 +161,23 @@ class StoryItem { ); } + factory StoryItem.widget({ + required Widget widget, + required StoryController controller, + Key? key, + bool shown = false, + Duration? duration, + }) { + return StoryItem( + Container( + key: key, + child: widget, + ), + shown: shown, + duration: duration ?? Duration(seconds: 3), + ); + } + /// Shorthand for creating inline image. [controller] should be same instance as /// one passed to the `StoryView` factory StoryItem.inlineImage({ From 4ae2dbef97980e702a13c47dbaad6eda26195302 Mon Sep 17 00:00:00 2001 From: Lucas Tonussi Date: Tue, 23 Nov 2021 09:26:22 -0300 Subject: [PATCH 2/8] add comment --- lib/widgets/story_view.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index 0854061f..7e35bfe1 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -161,6 +161,8 @@ class StoryItem { ); } + /// Factory constructor for custom widgets. [controller] should be same instance as + /// one passed to the `StoryView` factory StoryItem.widget({ required Widget widget, required StoryController controller, From 805600c2b16a51153952f3bd05f2cfb433282a55 Mon Sep 17 00:00:00 2001 From: Lucas Tonussi Date: Tue, 23 Nov 2021 16:35:25 -0300 Subject: [PATCH 3/8] remove container --- lib/widgets/story_view.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index 9c3388fc..9e820346 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -171,10 +171,7 @@ class StoryItem { Duration? duration, }) { return StoryItem( - Container( - key: key, - child: widget, - ), + widget, shown: shown, duration: duration ?? Duration(seconds: 3), ); From 8a6706b7a7d32e9b242f05690a5b9b8d7ead856a Mon Sep 17 00:00:00 2001 From: lstonussi Date: Sun, 28 Nov 2021 22:06:44 -0300 Subject: [PATCH 4/8] create param to show or not StoryProgressIndicator --- lib/widgets/story_view.dart | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index 18003d00..31f016ac 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -395,6 +395,9 @@ class StoryView extends StatefulWidget { /// The pages to displayed. final List storyItems; + /// Show or not story progress indicator. + final bool? showStoryProgressIndicator; + /// Callback for when a full cycle of story is shown. This will be called /// each time the full story completes when [repeat] is set to `true`. final VoidCallback? onComplete; @@ -425,6 +428,7 @@ class StoryView extends StatefulWidget { StoryView({ required this.storyItems, required this.controller, + this.showStoryProgressIndicator, this.onComplete, this.onStoryShow, this.progressPosition = ProgressPosition.top, @@ -656,6 +660,7 @@ class StoryViewState extends State with TickerProviderStateMixin { indicatorHeight: widget.inline ? IndicatorHeight.small : IndicatorHeight.large, + showStoryProgressIndicator: widget.showStoryProgressIndicator, ), ), ), @@ -743,11 +748,12 @@ class PageBar extends StatefulWidget { final List pages; final Animation? animation; final IndicatorHeight indicatorHeight; - + final bool? showStoryProgressIndicator; PageBar( this.pages, this.animation, { this.indicatorHeight = IndicatorHeight.large, + this.showStoryProgressIndicator, Key? key, }) : super(key: key); @@ -791,11 +797,15 @@ class PageBarState extends State { child: Container( padding: EdgeInsets.only( right: widget.pages.last == it ? 0 : this.spacing), - child: StoryProgressIndicator( - isPlaying(it) ? widget.animation!.value : (it.shown ? 1 : 0), - indicatorHeight: - widget.indicatorHeight == IndicatorHeight.large ? 5 : 3, - ), + child: widget.showStoryProgressIndicator ?? false + ? SizedBox() + : StoryProgressIndicator( + isPlaying(it) + ? widget.animation!.value + : (it.shown ? 1 : 0), + indicatorHeight: + widget.indicatorHeight == IndicatorHeight.large ? 5 : 3, + ), ), ); }).toList(), From f46210294c015a172d95a4208f3bb82007d6e88e Mon Sep 17 00:00:00 2001 From: lstonussi Date: Tue, 1 Nov 2022 14:39:53 -0300 Subject: [PATCH 5/8] added property to change current story color --- lib/widgets/story_view.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index dbccabd9..3f2a45aa 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -397,6 +397,9 @@ class StoryView extends StatefulWidget { /// Show or not story progress indicator. final bool? showStoryProgressIndicator; + /// Define current story progress color + final Color? activeStoryProgressColor; + /// Callback for when a full cycle of story is shown. This will be called /// each time the full story completes when [repeat] is set to `true`. final VoidCallback? onComplete; @@ -434,6 +437,7 @@ class StoryView extends StatefulWidget { this.repeat = false, this.inline = false, this.onVerticalSwipeComplete, + this.activeStoryProgressColor, }); @override @@ -660,6 +664,7 @@ class StoryViewState extends State with TickerProviderStateMixin { ? IndicatorHeight.small : IndicatorHeight.large, showStoryProgressIndicator: widget.showStoryProgressIndicator, + activeStoryProgressColor: widget.activeStoryProgressColor, ), ), ), @@ -748,11 +753,14 @@ class PageBar extends StatefulWidget { final Animation? animation; final IndicatorHeight indicatorHeight; final bool? showStoryProgressIndicator; + final Color? activeStoryProgressColor; + PageBar( this.pages, this.animation, { this.indicatorHeight = IndicatorHeight.large, this.showStoryProgressIndicator, + this.activeStoryProgressColor, Key? key, }) : super(key: key); @@ -804,6 +812,7 @@ class PageBarState extends State { : (it.shown ? 1 : 0), indicatorHeight: widget.indicatorHeight == IndicatorHeight.large ? 5 : 3, + activeStoryProgressColor: widget.activeStoryProgressColor, ), ), ); @@ -818,10 +827,12 @@ class StoryProgressIndicator extends StatelessWidget { /// From `0.0` to `1.0`, determines the progress of the indicator final double value; final double indicatorHeight; + final Color? activeStoryProgressColor; StoryProgressIndicator( this.value, { this.indicatorHeight = 5, + this.activeStoryProgressColor, }); @override @@ -831,7 +842,9 @@ class StoryProgressIndicator extends StatelessWidget { this.indicatorHeight, ), foregroundPainter: IndicatorOval( - Colors.white.withOpacity(0.8), + activeStoryProgressColor == null + ? Colors.white.withOpacity(0.8) + : activeStoryProgressColor!.withOpacity(0.8), this.value, ), painter: IndicatorOval( From d78dd56931787022ec98252ce46b32a27be7825e Mon Sep 17 00:00:00 2001 From: lstonussi Date: Tue, 1 Nov 2022 15:11:48 -0300 Subject: [PATCH 6/8] keeping the white background in past stories --- lib/widgets/story_view.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index 3f2a45aa..47fb5003 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -813,6 +813,7 @@ class PageBarState extends State { indicatorHeight: widget.indicatorHeight == IndicatorHeight.large ? 5 : 3, activeStoryProgressColor: widget.activeStoryProgressColor, + isCurrent: isPlaying(it), ), ), ); @@ -828,11 +829,13 @@ class StoryProgressIndicator extends StatelessWidget { final double value; final double indicatorHeight; final Color? activeStoryProgressColor; + final bool isCurrent; StoryProgressIndicator( this.value, { this.indicatorHeight = 5, this.activeStoryProgressColor, + required this.isCurrent, }); @override @@ -842,9 +845,11 @@ class StoryProgressIndicator extends StatelessWidget { this.indicatorHeight, ), foregroundPainter: IndicatorOval( - activeStoryProgressColor == null - ? Colors.white.withOpacity(0.8) - : activeStoryProgressColor!.withOpacity(0.8), + isCurrent + ? activeStoryProgressColor == null + ? Colors.white.withOpacity(0.8) + : activeStoryProgressColor!.withOpacity(0.8) + : Colors.white.withOpacity(0.8), this.value, ), painter: IndicatorOval( From b8e4fe756e29cdd59d80aedfdffa18e50cba3832 Mon Sep 17 00:00:00 2001 From: Maria Clara Almeida Souza Date: Wed, 23 Nov 2022 11:40:58 -0300 Subject: [PATCH 7/8] chore: add function --- lib/widgets/story_image.dart | 3 +-- lib/widgets/story_view.dart | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/widgets/story_image.dart b/lib/widgets/story_image.dart index 22dda158..64435be1 100644 --- a/lib/widgets/story_image.dart +++ b/lib/widgets/story_image.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'dart:ui' as ui; import 'package:flutter/material.dart'; -import 'package:flutter/painting.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import '../utils.dart'; @@ -46,7 +45,7 @@ class ImageLoader { this.state = LoadState.success; - PaintingBinding.instance!.instantiateImageCodec(imageBytes).then( + PaintingBinding.instance.instantiateImageCodec(imageBytes).then( (codec) { this.frames = codec; onComplete(); diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index 47fb5003..41e0e23d 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:math'; -import 'dart:ui'; import 'package:collection/collection.dart' show IterableExtension; import 'package:flutter/material.dart'; @@ -427,6 +426,8 @@ class StoryView extends StatefulWidget { // Controls the playback of the stories final StoryController controller; + final bool Function()? canGoToNext; + StoryView({ required this.storyItems, required this.controller, @@ -438,6 +439,7 @@ class StoryView extends StatefulWidget { this.inline = false, this.onVerticalSwipeComplete, this.activeStoryProgressColor, + this.canGoToNext, }); @override @@ -497,8 +499,15 @@ class StoryViewState extends State with TickerProviderStateMixin { break; case PlaybackState.next: - _removeNextHold(); - _goForward(); + final result = widget.canGoToNext?.call() ?? true; + + if (result) { + _removeNextHold(); + _goForward(); + } else { + widget.controller.play(); + } + break; case PlaybackState.previous: From 94c7ec07560fad083e77f0295c5e45c2b4bc6788 Mon Sep 17 00:00:00 2001 From: lstonussi Date: Tue, 18 Apr 2023 11:51:06 -0300 Subject: [PATCH 8/8] add param background color --- lib/widgets/story_view.dart | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/widgets/story_view.dart b/lib/widgets/story_view.dart index 41e0e23d..79a3f853 100644 --- a/lib/widgets/story_view.dart +++ b/lib/widgets/story_view.dart @@ -837,13 +837,14 @@ class StoryProgressIndicator extends StatelessWidget { /// From `0.0` to `1.0`, determines the progress of the indicator final double value; final double indicatorHeight; - final Color? activeStoryProgressColor; + final Color? activeStoryProgressColor, backgroundStoryProgressColor; final bool isCurrent; StoryProgressIndicator( this.value, { this.indicatorHeight = 5, this.activeStoryProgressColor, + this.backgroundStoryProgressColor, required this.isCurrent, }); @@ -858,11 +859,15 @@ class StoryProgressIndicator extends StatelessWidget { ? activeStoryProgressColor == null ? Colors.white.withOpacity(0.8) : activeStoryProgressColor!.withOpacity(0.8) - : Colors.white.withOpacity(0.8), + : backgroundStoryProgressColor == null + ? Colors.white.withOpacity(0.8) + : backgroundStoryProgressColor!.withOpacity(0.8), this.value, ), painter: IndicatorOval( - Colors.white.withOpacity(0.4), + backgroundStoryProgressColor == null + ? Colors.white.withOpacity(0.4) + : backgroundStoryProgressColor!.withOpacity(.4), 1.0, ), );