Story Block (Flutter)
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
For android:
StoryBlock is a heavy object containing multiple instances of the player, Heavy-lifting UI elements, and intensive background tasks, Beware that the recommended number of the StoryBlock being used in a single screen is 1. However, in a wide range of new Android devices, 2 instances might work alright. Any number of StoryBlock above this limitation is not recommended by the Firework team and is not supported.
Currently, there are eight source types of the story block:
Discover
Channel
Playlist
Dynamic Content
Hashtag Playlist
SKU
Single Content
import 'package:fw_flutter_sdk/fw_flutter_sdk.dart';
import 'package:visibility_detector/visibility_detector.dart';
StoryBlockController? _storyBlockController;
/// discover
StoryBlock(
height: 400,
source: StoryBlockSource.discover,
)
/// channel
StoryBlock(
height: 400,
source: StoryBlockSource.channel,
channel: "your encoded channel id",
)
/// playlist
StoryBlock(
height: 400,
source: StoryBlockSource.playlist,
channel: "your encoded channel id",
playlist: "your encoded playlist id",
)
/// dynamic content
StoryBlock(
height: 400,
source: StoryBlockSource.dynamicContent,
dynamicContentParameters: const {
'<cohort key>': ['<cohort value1>', '<cohort value2>']
},
)
/// hashtag playlist
StoryBlock(
height: 400,
source: StoryBlockSource.hashtagPlaylist,
channel: "your encoded channel id",
hashtagFilterExpression: "<hashtag filter expression>",
)
/// sku
StoryBlock(
height: 400,
source: StoryBlockSource.sku,
channel: "your encoded channel id",
productIds: ["prodct_id_1", "prodct_id_2"],
)
/// single content
StoryBlock(
height: 400,
source: StoryBlockSource.singleContent,
contentId: "your encoded video or live stream id"
);
StoryBlock(
height: 400,
source: StoryBlockSource.discover,
cornerRadius: 20,
);
StoryBlock
widget provides onStoryBlockLoadFinished
property for setting story block loading result callback.
StoryBlock(
height: 400,
source: StoryBlockSource.discover,
);
StoryBlock
widget provides onStoryBlockEmpty
property for setting story block empty callback. The callback is triggered when there are no items in the story block. For example, you could hide the widget when the callback is triggered. The callback is triggered in the following scenarios:
Load successfully but the back end returns an empty list
The load failed and the list is empty
StoryBlock(
source: StoryBlock.discover,
onStoryBlockEmpty: (error) {
// Hide the widget
},
);
StoryBlockController? _storyBlockController;
StoryBlock(
height: 400,
source: StoryBlockSource.discover,
onStoryBlockCreated: (controller) {
_storyBlockController = controller;
},
);
// Play story block
_storyBlockController?.play();
// Pause story block
_storyBlockController?.pause();
StoryBlockController? _storyBlockController;
StoryBlock(
height: 400,
source: StoryBlockSource.discover,
onStoryBlockCreated: (controller) {
_storyBlockController = controller;
},
);
// Open fullscreen story block
// Only supported on iOS
_storyBlockController?.openFullscreen();
To enable PiP outside the iOS app, you also need to add "Audio, Airplay, and Picture in Picture" background mode via Signing & Capabilities in your iOS project settings(as shown in the following screenshot). More information about this can be found here: Apple Documentation
// Enable PiP for StoryBlock widget
StoryBlock(
height: 400,
source: StoryBlockSource.discover,
enablePictureInPicture: true,
);
Generally, if you put the story block widget as the child of ListView, it will be rebuilt when scrolling the widget out of the view box. You could set wantKeepAlive
as true
to make the story block widget keep alive when scrolling the widget out of the view box.
StoryBlock(
height: 400,
source: StoryBlockSource.discover,
// Keep the widget alive when scrolling the widget out of the view box
wantKeepAlive: true,
);
Please refer to Player configurations (Flutter).