Skip to content

Commit

Permalink
Merge pull request #2 from javarahulsharma/expandable
Browse files Browse the repository at this point in the history
bug fix code refactor
  • Loading branch information
javarahulsharma authored Mar 28, 2024
2 parents ed0ad75 + d94e11b commit 496bc01
Showing 1 changed file with 133 additions and 137 deletions.
270 changes: 133 additions & 137 deletions lib/widgets/story_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ class StoryItem {
loadingWidget: loadingWidget,
errorWidget: errorWidget,
),
SafeArea(
child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(),
),
)
Positioned(
right: 0,
left: 0,
bottom:50,
child: caption ?? SizedBox()
),
],
),
),
caption: Container(
caption: caption ?? Container(
width: double.infinity,
margin: EdgeInsets.only(
bottom: 24,
Expand All @@ -165,7 +165,7 @@ class StoryItem {
/// one passed to the `StoryView`
factory StoryItem.inlineImage({
required String url,
Text? caption,
Widget? caption,
required StoryController controller,
Key? key,
BoxFit imageFit = BoxFit.cover,
Expand Down Expand Up @@ -195,7 +195,14 @@ class StoryItem {
loadingWidget: loadingWidget,
errorWidget: errorWidget,
),
Positioned(
right: 0,
left: 0,
bottom:50,
child: caption ?? SizedBox()
),
],

),
),
),
Expand All @@ -204,16 +211,17 @@ class StoryItem {
bottom: Radius.circular(roundedBottom ? 8 : 0),
),
),
caption: Container(
margin: EdgeInsets.only(bottom: 16),
padding: captionOuterPadding?? EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: Align(
alignment: Alignment.bottomLeft,
child: Container(
child: caption?? const SizedBox.shrink(),
width: double.infinity,
),
caption: caption ?? Container(
width: double.infinity,
margin: EdgeInsets.only(
bottom: 24,
),
padding: captionOuterPadding?? EdgeInsets.symmetric(
horizontal: 24,
vertical: 8,
),
color: caption != null ? Colors.black54 : Colors.transparent,
child: caption?? const SizedBox.shrink(),
),
shown: shown,
duration: duration ?? Duration(seconds: 3),
Expand Down Expand Up @@ -247,19 +255,26 @@ class StoryItem {
loadingWidget: loadingWidget,
errorWidget: errorWidget,
),
Positioned(
right: 0,
left: 0,
bottom:50,
child: caption ?? SizedBox()
),
],
),
),
caption: Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
margin: EdgeInsets.only(bottom: 24),
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
color:
caption != null ? Colors.black54 : Colors.transparent,
child: caption?? const SizedBox.shrink(),
caption: caption ?? Container(
width: double.infinity,
margin: EdgeInsets.only(
bottom: 24,
),
padding: EdgeInsets.symmetric(
horizontal: 24,
vertical: 8,
),
color: caption != null ? Colors.black54 : Colors.transparent,
child: caption?? const SizedBox.shrink(),
),
shown: shown,
duration: duration ?? Duration(seconds: 10));
Expand All @@ -272,7 +287,7 @@ class StoryItem {
ImageProvider image, {
Key? key,
BoxFit imageFit = BoxFit.fitWidth,
String? caption,
Widget? caption,
bool shown = false,
Duration? duration,
}) {
Expand All @@ -290,46 +305,27 @@ class StoryItem {
fit: imageFit,
),
),
SafeArea(
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
margin: EdgeInsets.only(
bottom: 24,
),
padding: EdgeInsets.symmetric(
horizontal: 24,
vertical: 8,
),
color:
caption != null ? Colors.black54 : Colors.transparent,
child: caption != null
? Text(
caption,
style: TextStyle(
fontSize: 15,
color: Colors.white,
),
textAlign: TextAlign.center,
)
: SizedBox(),
),
),
)
Positioned(
right: 0,
left: 0,
bottom:50,
child: caption ?? SizedBox()
),
],
),
),
caption: caption != null
? Text(
caption,
style: TextStyle(
fontSize: 15,
color: Colors.white,
caption: caption ?? Container(
width: double.infinity,
margin: EdgeInsets.only(
bottom: 24,
),
textAlign: TextAlign.center,
)
: SizedBox(),
padding: EdgeInsets.symmetric(
horizontal: 24,
vertical: 8,
),
color: caption != null ? Colors.black54 : Colors.transparent,
child: caption?? const SizedBox.shrink(),
),
shown: shown,
duration: duration ?? Duration(seconds: 3));
}
Expand All @@ -340,7 +336,7 @@ class StoryItem {
factory StoryItem.inlineProviderImage(
ImageProvider image, {
Key? key,
Text? caption,
Widget? caption,
bool shown = false,
bool roundedTop = true,
bool roundedBottom = false,
Expand Down Expand Up @@ -376,7 +372,18 @@ class StoryItem {
),
),
),
caption: caption,
caption: caption ?? Container(
width: double.infinity,
margin: EdgeInsets.only(
bottom: 24,
),
padding: EdgeInsets.symmetric(
horizontal: 24,
vertical: 8,
),
color: caption != null ? Colors.black54 : Colors.transparent,
child: caption?? const SizedBox.shrink(),
),
shown: shown,
duration: duration ?? Duration(seconds: 3),
);
Expand Down Expand Up @@ -467,11 +474,6 @@ class StoryViewState extends State<StoryView> with TickerProviderStateMixin {
item ??= widget.storyItems.last;
return item?.view ?? Container();
}
Widget get _currentCaption {
var item = widget.storyItems.firstWhereOrNull((it) => !it!.shown);
item ??= widget.storyItems.last;
return item?.caption ?? Container();
}

@override
void initState() {
Expand Down Expand Up @@ -677,74 +679,68 @@ class StoryViewState extends State<StoryView> with TickerProviderStateMixin {
),
),
),
Align(
alignment: Alignment.centerRight,
heightFactor: 1,
child: GestureDetector(
onTapDown: (details) {
widget.controller.pause();
},
onTapCancel: () {
widget.controller.play();
},
onTapUp: (details) {
// if debounce timed out (not active) then continue anim
if (_nextDebouncer?.isActive == false) {
Align(
alignment: Alignment.centerRight,
heightFactor: 0.7,
child: GestureDetector(
onTapDown: (details) {
widget.controller.pause();
},
onTapCancel: () {
widget.controller.play();
} else {
widget.controller.next();
}
},
onVerticalDragStart: widget.onVerticalSwipeComplete == null
? null
: (details) {
widget.controller.pause();
},
onVerticalDragCancel: widget.onVerticalSwipeComplete == null
? null
: () {
widget.controller.play();
},
onVerticalDragUpdate: widget.onVerticalSwipeComplete == null
? null
: (details) {
if (verticalDragInfo == null) {
verticalDragInfo = VerticalDragInfo();
}

verticalDragInfo!.update(details.primaryDelta!);

// TODO: provide callback interface for animation purposes
},
onVerticalDragEnd: widget.onVerticalSwipeComplete == null
? null
: (details) {
widget.controller.play();
// finish up drag cycle
if (!verticalDragInfo!.cancel &&
widget.onVerticalSwipeComplete != null) {
widget.onVerticalSwipeComplete!(
verticalDragInfo!.direction);
}

verticalDragInfo = null;
},
),),
Align(
alignment: Alignment.centerLeft,
heightFactor: 1,
child: SizedBox(
child: GestureDetector(onTap: () {
widget.controller.previous();
}),
width: 70),
),
Positioned(
bottom: 10,
left: 0,
right: 0,
child: _currentCaption
),
},
onTapUp: (details) {
// if debounce timed out (not active) then continue anim
if (_nextDebouncer?.isActive == false) {
widget.controller.play();
} else {
widget.controller.next();
}
},
onVerticalDragStart: widget.onVerticalSwipeComplete == null
? null
: (details) {
widget.controller.pause();
},
onVerticalDragCancel: widget.onVerticalSwipeComplete == null
? null
: () {
widget.controller.play();
},
onVerticalDragUpdate: widget.onVerticalSwipeComplete == null
? null
: (details) {
if (verticalDragInfo == null) {
verticalDragInfo = VerticalDragInfo();
}

verticalDragInfo!.update(details.primaryDelta!);

// TODO: provide callback interface for animation purposes
},
onVerticalDragEnd: widget.onVerticalSwipeComplete == null
? null
: (details) {
widget.controller.play();
// finish up drag cycle
if (!verticalDragInfo!.cancel &&
widget.onVerticalSwipeComplete != null) {
widget.onVerticalSwipeComplete!(
verticalDragInfo!.direction);
}

verticalDragInfo = null;
},
),),
Align(
alignment: Alignment.centerLeft,
heightFactor: 0.7,
child: SizedBox(
child: GestureDetector(onTap: () {
widget.controller.previous();
}),
width: 70),
)

],
),
Expand Down

0 comments on commit 496bc01

Please sign in to comment.