搜尋套件、儲存庫與 APP 分類

story 封面
套件詳情v1.1.0

story

Instagram stories-like 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 項

原始碼儲存庫

使用此套件的專案