搜索插件、代码仓与 APP 分类

story 封面
插件详情v1.1.0

story

Instagram 话题类似 UI,具有丰富的动画和可定制性。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
9430
喜欢数
348
Pub 分数
150

安装插件

flutter pub add story

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

该故事包提供了一种受 Instagram Stories 启发的用户界面,具有流畅的动画和高度可定制性。它使开发者能够创建可交互、可滑动的故事卡片,支持自定义过渡效果、计时器和内容布局。适用于需要动态叙事体验的应用程序,支持移动、网页和桌面等多种平台。该包专为与 Flutter 的小部件系统轻松集成而设计,并提供了丰富的样式选项,用于外观和行为的自定义。

适合场景

  • 创建社交媒体风格的故事动态
  • 构建交互式教程或入门流程
  • 显示限时内容更新
  • 设计引人入胜的营销活动
  • 实现用户个人资料故事亮点

主要特点

  • 丰富而生动的故事过渡
  • 可自定义的故事卡片布局
  • 跨平台滑动手势支持
  • 可配置的持续时间和进度指示器
  • 可扩展的主题和样式选项

适合对象

  • 开发社交功能的开发者
  • 需要限时内容交付的应用程序
  • 寻求动画UI组件的设计师
  • 跨平台应用程序,具有类似故事的界面

使用建议

  • 在导航过程中需要仔细处理状态
  • 可能会影响大型故事集的性能
  • 有限的内置分析或跟踪
  • 未针对超长故事进行优化
  • 依赖外部动画库以实现高级效果

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

version likes popularity License: MIT all contributors

Instagram stories like UI with rich animations and customizability.

final 2

Usage

StoryPageView requires at least three arguments: itemBuilder, pageLength, and storyLength.

/// Minimum example to explain the usage.
return Scaffold(
  body: StoryPageView(
    itemBuilder: (context, pageIndex, storyIndex) {
      return Center(
        child: Text("Index of PageView: $pageIndex Index of story on each page: $storyIndex"),
      );
    },
    storyLength: (pageIndex) {
      return 3;
    },
    pageLength: 4,
  );
  • itemBuilder builds the content of each story and is called with the index of the pageView and the index of the story on the page.

  • storyLength decides the length of story for each page. The example above always returns 3, but it should depend on pageIndex.

  • pageLength is just the length of StoryPageView

The example above just shows 12 stories by 4 pages, which is not practical.

This one is the proper usage, extracted from example.

return Scaffold(
  body: StoryPageView(
    itemBuilder: (context, pageIndex, storyIndex) {
      final user = sampleUsers[pageIndex];
      final story = user.stories[storyIndex];
      return Stack(
        children: [
          Positioned.fill(
            child: Container(color: Colors.black),
          ),
          Positioned.fill(
            child: Image.network(
              story.imageUrl,
              fit: BoxFit.cover,
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 44, left: 8),
            child: Row(
              children: [
                Container(
                  height: 32,
                  width: 32,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: NetworkImage(user.imageUrl),
                      fit: BoxFit.cover,
                    ),
                    shape: BoxShape.circle,
                  ),
                ),
                const SizedBox(
                  width: 8,
                ),
                Text(
                  user.userName,
                  style: TextStyle(
                    fontSize: 17,
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
        ],
      );
    },
    gestureItemBuilder: (context, pageIndex, storyIndex) {
      return Align(
        alignment: Alignment.topRight,
        child: Padding(
          padding: const EdgeInsets.only(top: 32),
          child: IconButton(
            padding: EdgeInsets.zero,
            color: Colors.white,
            icon: Icon(Icons.close),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
        ),
      );
    },
    pageLength: sampleUsers.length,
    storyLength: (int pageIndex) {
      return sampleUsers[pageIndex].stories.length;
    },
    onPageLimitReached: () {
      Navigator.pop(context);
    },
  ),
);
  • gestureItemBuilder builds widgets that need gesture actions

In this case, IconButton to close the page is in the callback.

You CANNOT place the gesture widgets in itemBuilder as they are covered and disabled by the default story gestures.

  • onPageLimitReached is called when the very last story is finished.

  • It is recommended to use data model with two layers. In this case, UserModel which has the list of StoryModel

/// Example Data Model
class UserModel {
  UserModel(this.stories, this.userName, this.imageUrl);

  final List<StoryModel> stories;
  final String userName;
  final String imageUrl;
}

class StoryModel {
  StoryModel(this.imageUrl);

  final String imageUrl;
}
StoryImage

If you show images in StoryPageView, use StoryImage. It can stop the indicator until the image is fully loaded.

StoryImage(
  /// key is required
  key: ValueKey(story.imageUrl),
  imageProvider: NetworkImage(
    story.imageUrl,
  ),
  fit: BoxFit.fitWidth,
)

Be sure to assign the unique key value for each image, otherwise the image loading will not be handled properly.

indicatorAnimationController

If you stop/start the animation of the story with your custom widgets, use indicatorAnimationController

class _StoryPageState extends State<StoryPage> {
  late ValueNotifier<IndicatorAnimationCommand> indicatorAnimationController;

  @override
  void initState() {
    super.initState();
    indicatorAnimationController = ValueNotifier<IndicatorAnimationCommand>(
        IndicatorAnimationCommand.resume);
  }

  @override
  void dispose() {
    indicatorAnimationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: StoryPageView(
        indicatorAnimationController: indicatorAnimationController,
        ...,
      ),
    );
  }
}

Once the instance is passed to StoryPageView, you can stop handle the indicator by the methods below.


/// To pause the indicator
indicatorAnimationController.value = IndicatorAnimationCommand.pause;

/// To resume the indicator
indicatorAnimationController.value = IndicatorAnimationCommand.resume;

Contributors

Santa Takahashi
Santa Takahashi

💻
Isaias Mejia de los Santos
Isaias Mejia de los Santos

💻
Медик
Медик

💻
Alperen Soysal
Alperen Soysal

💻
AtixD
AtixD

💻
harshitFinmapp
harshitFinmapp

💻
dmitry-kotorov
dmitry-kotorov

💻
sachin kumar rajput
sachin kumar rajput

💻
Mohamed Othman
Mohamed Othman

💻

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目