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

GitHub 儲存庫kvs-coder/grouped_content_custom_scroll_view

分組內容自定義滾動視圖

GroupedContentCustomScrollView 小工具。基於 Sliver 小工具建構一個漂亮的表格,條目依標題分組。

分組內容自定義滾動視圖 專案封面
星標
5
分支
1
最近推送(UTC)
2021年11月13日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

sliver_grouped_list

SliverGroupedList Widget

Build a beautiful sliver with a custom header, footer and body, which can be divided by groups with a header for each group and a list of entries.

Getting Started

  • Go inside pubspec.yaml file
  • Add this to your package's pubspec.yaml file:
dependencies:
     sliver_grouped_list: ^1.0.4
  • Run flutter pub get

How to use

Go to your widget .dart file and do import

import 'package:sliver_grouped_list/sliver_grouped_list.dart';

Inside your widget's Widget build(BuildContext context) method set as body the SliverGroupedList with explicitly showing the types of bodyHeader and bodyEntry.

// [Header] is the type of a group header
// [Entry] is the type of every entry in the list related to the group
body: SliverGroupedList<Header, Entry>()

Implement all required constructor parameters.

As a result the custom scroll view will contain the content of the passed data. Optionally you may add a RenderObjectWidget widget like SliverGrid or SliverList header section to the scroll view, and a footer as well.

Here is an example which is displayed in the GIF from above.

import 'package:flutter/material.dart';
import 'package:sliver_grouped_list/sliver_grouped_list.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  static const double _kHeight = 150.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Example'),
      ),
      body: SliverGroupedList<String, String>(
        data: {
          'A': ['My best friend', 'Good friend of mine', 'Guy I do not know'],
          'B': ['My cat', 'My dog', 'My fish', 'My bird'],
          'C': ['My mom', 'My dad', 'My sis']
        },
        header: SliverGrid.count(
          crossAxisCount: 3,
          children: [
            Container(color: Colors.white, height: _kHeight),
            Container(color: Colors.black, height: _kHeight),
            Container(color: Colors.grey, height: _kHeight),
            Container(color: Colors.grey, height: _kHeight),
            Container(color: Colors.white, height: _kHeight),
            Container(color: Colors.black, height: _kHeight),
            Container(color: Colors.black, height: _kHeight),
            Container(color: Colors.grey, height: _kHeight),
            Container(color: Colors.white, height: _kHeight),
          ],
        ),
        bodyHeaderMinHeight: 60.0,
        bodyHeaderMaxHeight: 100.0,
        bodyHeaderPinned: true,
        bodyHeaderFloating: false,
        bodyHeaderBuilder: (_, header) => Container(
          alignment: Alignment.center,
          child: Text(
            header,
            style: TextStyle(color: Colors.white),
          ),
          color: Colors.blue,
        ),
        bodyPlaceholderBuilder: (_, header) => Card(
              color: Colors.lightBlueAccent,
              child: Container(
                  height: _kHeight,
                  alignment: Alignment.center,
                  child: Text(
                    "There are no items available",
                    style: TextStyle(color: Colors.grey),
                  ))),
        bodyEntryBuilder: (_, index, item) => GestureDetector(
          onTap: () {
            print(item);
            print(index);
          },
          child: Card(
              color: Colors.lightBlueAccent,
              child: Container(
                  height: _kHeight,
                  alignment: Alignment.center,
                  child: Text(
                    item,
                    style: TextStyle(color: Colors.white),
                  ))),
        ),
        footer: SliverFixedExtentList(
          itemExtent: _kHeight,
          delegate: SliverChildListDelegate(
            [
              Container(color: Colors.black),
              Container(color: Colors.white),
              Container(color: Colors.grey),
              Container(color: Colors.black),
              Container(color: Colors.white),
              Container(color: Colors.grey),
            ],
          ),
        ),
      ),
    );
  }
}

License

Under MIT License

Sponsorhip

If you think that my repo helped you to solve the issues you struggle with, please don't be shy and sponsor :-)

Victor GitHub avatar
GitHub 作者

Victor ↗

Chicago, IL官方網站 ↗
語言DartSwiftKotlinObjective-C

分類

使用的依賴

依賴清單 2 項

  • flutter{"sdk":"flutter"}
  • flutter_test開發依賴{"sdk":"flutter"}

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗