Skip to main content

FeedStoriesWidget

The FeedStoriesWidget is a widget that displays a feed of stories.

class FeedExample extends StatelessWidget {
const FeedExample({super.key});


Widget build(BuildContext context) {
return Column(
children: [
// other widgets
FeedStoriesWidget(
feed: '<your feed id>',
),
],
);
}
}

Parameters

ParameterRequiredDescription
feedyesThe identifier of the feed to fetch stories from.
controllernoOptional controller to manage the feed.
heightnoSpecifies the height of the widget. Defaults to 120.0.
decoratornoOptional decorator for customizing the appearance.
loaderBuildernoOptional builder for the loading widget.
errorBuildernoOptional builder for the error widget.
storyBuildernoOptional builder for individual story widgets.
favoritesBuildernoOptional builder for the favorites widget.
storiesLoadednoCalled when stories are loaded in the widget.
storiesLoadErrornoCalled when an error occurs while loading stories.

FeedStoryDecorator

The FeedStoryDecorator is a class that provides a way to customize the appearance of the stories in the feed. It applies its parameters to the default story builder, or you can use it in your own builder.

class FeedExample extends StatelessWidget {
const FeedExample({super.key});


Widget build(BuildContext context) {
return Column(
children: [
// other widgets
FeedStoriesWidget(
feed: '<your feed id>',
decorator: const FeedStoryDecorator(
storyPadding: 12.0,
feedPadding: EdgeInsets.only(top: 4.0),
loaderAspectRatio: 1 / 1,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
textFontSize: 14.0,
textPadding: EdgeInsets.all(8.0),
borderColor: Colors.deepPurple,
borderWidth: 2.0,
borderPadding: 4.0,
),
),
],
);
}
}

Parameters

VariableTypeDefaultDescription
borderRadiusBorderRadiusGeometryBorderRadius.all(Radius.circular(8)),Border radius for the story widget
feedPaddingEdgeInsetsGeometryEdgeInsets.all(0.0)Padding for the list of stories
textPaddingEdgeInsetsGeometryEdgeInsets.all(4.0)Padding for text in the list of stories
storyPaddingdouble8.0Padding between stories in the list
textFontSizedouble12.0Text font size
loaderAspectRatiodouble1 / 1Loader aspect ratio, used in default loader
favouriteAspectRatiodouble1 / 1Favorites item aspect ratio in list, used in default favorites builder
loaderDecoratorLoaderDecoratorbaseColor: Color.fromARGB(255, 224, 224, 224)
highlightColor: Color.fromARGB(255, 158, 158, 158)
Used to customize loader
foregroundDecorationBoxDecorationLinearGradientUsed to customize placeholder
showBorderbooltrueEnables border around story, that indicates story has been opened
borderWidthdouble1.0Width of border
borderPaddingdouble2.0Padding between border and story content
borderColorColorColors.black87Color of border
textStyleTextStylenullText style in the story list
scrollPhysicsScrollPhysicsnullScroll physics in story list
animateScrollToItemsboolfalseAnimate scroll to last viewed stories in story list
scrollCurveCurveCurves.easeInOutCurve for scroll animation
scrollDurationDurationDuration(milliseconds: 300)Scroll animation duration

Builders

The FeedStoriesWidget has four builders:

  1. storyBuilder: A builder that creates a widget for each story in the feed;
class FeedExample extends StatelessWidget {
const FeedExample({super.key});


Widget build(BuildContext context) {
return Column(
children: [
FeedStoriesWidget(
feed: '<your feed id>',
storyBuilder: (story, decorator) {
// Additional customization for the story widget
return CustomStoryBuilder(
story,
onStoryTap: (story) {
// Custom action on story tap
print('Story tapped: ${story.title}');
},
);
},
),
],
);
}
}

class CustomStoryBuilder extends BaseStoryBuilder {
const CustomStoryBuilder(super.story, {super.key, super.onStoryTap});


Widget build(BuildContext context) {
return GestureDetector(
onTap: () => onTap(story),
child: Stack(
children: [
Positioned.fill(
// use the StoryContentWidget to display the story content
child: StoryContentWidget(story: story),
),
const Positioned.fill(
child: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black87,
],
),
),
),
),
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
story.title,
style: TextStyle(
color: story.titleColor,
fontSize: 14,
),
),
),
),
],
),
);
}
}
  1. loaderBuilder: A builder that creates a widget for the loading state of the feed. To implement a custom loader, see instructions here;

  2. errorBuilder: A builder that creates a widget for the error state of the feed, by default it shows SizedBox.shrink() widget;

  3. favoritesBuilder: A builder that creates a widget for the favorites stories in the feed;

Callbacks

To receive event when stories are loaded you can use storiesLoaded callback:

class FeedExample extends StatelessWidget {
const FeedExample({super.key});


Widget build(BuildContext context) {
return Column(
children: [
FeedStoriesWidget(
feed: '<your feed id>',
storiesLoaded: (size, feed) {
print('Stories loaded: $size');
},
storiesLoadError: (reason) {
print(reason);
},
),
],
);
}
}

More stories callbacks can be found in the Events section.

FeedStoriesController

You can use FeedStoriesController to force reload the feed stories:

class FeedExample extends StatelessWidget {
FeedExample({super.key});

final feedStoriesController = FeedStoriesController();


Widget build(BuildContext context) {
return Column(
children: [
FeedStoriesWidget(
feed: '<your feed id>',
controller: feedStoriesController,
),
ElevatedButton(
onPressed: () async => await feedStoriesController.fetchFeedStories(),
child: const Text('Reload'),
),
],
);
}
}

Methods

  • fetchFeedStories() - reloads the feed stories;