{"id":19508064,"url":"https://github.com/wenlong-guo/flutter_multitype","last_synced_at":"2026-02-25T14:34:34.604Z","repository":{"id":44438144,"uuid":"508138373","full_name":"Wenlong-Guo/flutter_multitype","owner":"Wenlong-Guo","description":":fire::fire::fire:Easier and more flexible to create multiple types for Flutter ListView.","archived":false,"fork":false,"pushed_at":"2022-07-13T02:49:40.000Z","size":11730,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T07:04:10.249Z","etag":null,"topics":["android","dart","flutter","gridview","ios","listview","multi","type"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Wenlong-Guo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-28T03:15:43.000Z","updated_at":"2024-06-16T00:07:25.000Z","dependencies_parsed_at":"2022-07-13T12:50:27.779Z","dependency_job_id":null,"html_url":"https://github.com/Wenlong-Guo/flutter_multitype","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2Fflutter_multitype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2Fflutter_multitype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2Fflutter_multitype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wenlong-Guo%2Fflutter_multitype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wenlong-Guo","download_url":"https://codeload.github.com/Wenlong-Guo/flutter_multitype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250922198,"owners_count":21508289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dart","flutter","gridview","ios","listview","multi","type"],"created_at":"2024-11-10T23:03:29.156Z","updated_at":"2026-02-25T14:34:34.551Z","avatar_url":"https://github.com/Wenlong-Guo.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flutter Multitype\n[![License](https://img.shields.io/github/license/Wenlong-Guo/flutter_multitype)](https://github.com/Wenlong-Guo/flutter_multitype/blob/master/LICENSE)\n![Release](https://img.shields.io/github/v/release/Wenlong-Guo/flutter_multitype?include_prereleases)\n[![likes](https://badges.bar/flutter_multitype/likes)](https://pub.dev/packages/flutter_multitype/score)\n[![popularity](https://badges.bar/flutter_multitype/popularity)](https://pub.dev/packages/flutter_multitype/score)\n[![pub points](https://badges.bar/flutter_multitype/pub%20points)](https://pub.dev/packages/flutter_multitype/score)\n- [About Flutter Multitype](#about-flutter-multitype)\n- [Installing](#Installing)\n- [Function](#Function)\n- [Usage](#Usage)\n- [Advanced usage](#advanced-usage)\n    - [One to many](#one-to-many)\n    - [Register unsupported data of item widget](#register-unsupported-data-of-item-widget)\n    - [Easy to debug](#easy-to-debug)\n- [Screenshots](#screenshots)\n    - [Chat Sample](#chat-sample)\n    - [Media Sample](#media-sample)\n    - [Blog Sample](#blog-sample)\n- [Thanks](#thanks)\n- [关于作者](#关于作者)\n\n# About Flutter Multitype\n\n:fire::fire::fire:Easier and more flexible to create multiple types for Flutter ListView.\n\n# Installing\n\nAdd `flutter_multitype: ^0.9.2` to your `pubspec.yaml` file:\n\n```yaml\ndependencies:\n  flutter_multitype: ^0.9.2\n```\n\nImport get in files that it will be used:\n\n```dart\nimport 'package:flutter_multitype/multitype.dart';\n```\n\n# Function\n\n`flutter_multitype` can be used to decouple and improve readability when items in a ListView have\ndifferent types of layouts and are dynamically indeterminate .\n\n# Usage\n\none data bind one widget\n\n## Step 1. Create a data class, for example:\n\n```dart\nclass CategoryName {\n  String? title;\n\n  CategoryName(this.title);\n}\n\nclass CategorySubContent {\n  String? title;\n  String? url;\n\n  CategorySubContent(this.title, this.url);\n}\n```\n\n## Step 2. Create a class extends ItemViewBinder\u003cT\u003e, for example:\n\n```dart\nclass CategoryViewBinder extends ItemViewBinder\u003cCategoryName\u003e {\n  @override\n  Widget buildWidget(BuildContext context, CategoryName item, int index) {\n    return const Text(\"Category\");\n  }\n}\n\nclass ContentViewBinder extends ItemViewBinder\u003cList\u003cCategorySubContent\u003e\u003e {\n  @override\n  Widget buildWidget(BuildContext context, List\u003cCategorySubContent\u003e item, int index) {\n    return const Text(\"Content\");\n  }\n}\n```\n\n## Step 3. register your types and setup your ListView, for example:\n\n```dart\nclass _MediaPageState extends State\u003cMediaPage\u003e {\n  List\u003cdynamic\u003e items = Data.getMediaData();\n  MultiTypeAdapter adapter = MultiTypeAdapter.newInstance((adapter) {\n    adapter.register(CategoryViewBinder());\n    adapter.register(ContentViewBinder());\n    adapter.setDebugViewBinderEnable(isEnable: true);\n  });\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        title: const Text(\"Media Page\"),\n      ),\n      body: ListView.builder(\n        itemCount: items.length,\n        itemBuilder: (context, index) {\n          return adapter.getItemBuilder(context, index, items[index]);\n        },\n      ),\n    );\n  }\n}\n```\n\nMulti type item widget ListView is complete\n\n# Advanced usage\n\n## One to many\n\none data bind many widget,for example:\n\n```dart\n/// ChatMessage will be bind TextMeViewBinder、TextOtherViewBinder、UnknownMeViewBinder、UnknownOtherViewBinder four Widget\nMultiTypeAdapter adapter = MultiTypeAdapter.newInstance((adapter) {\nadapter.registerOneToMany\u003cChatMessage\u003e((position, item) {\n  var message = item as ChatMessage;\n  if (message.isMe == true) {\n    switch (message.type) {\n      case 0:\n        {\n          return TextMeViewBinder();\n        }\n      default:\n        {\n          return UnknownMeViewBinder();\n        }\n    }\n  } else {\n    switch (message.type) {\n      case 1:\n        {\n          return TextOtherViewBinder();\n        }\n      default:\n        {\n          return UnknownOtherViewBinder();\n        }\n    }\n  }\n});\n```\n\n## Register unsupported data of item widget\n\nIf someone items data have not register, it will be bind unsupportedViewBinder. For example: Old\nversion received new version data, you can show this unsupportedViewBinder for tips user update app.\nBut if your data is same type,this function is not suitable.You can use in different type data.\n\n```\nvoid registerUnsupportedViewBinder(ItemViewBinder unsupportedViewBinder)\n```\n\n## Easy to debug\nIf someone items data have not register, it will be bind debugViewBinder if someone items data have\nnot register,at the same time register unsupportedViewBinder and debugViewBinder, debugViewBinder\nwill be cover unsupportedViewBinder. Don't worry,debugViewBinder is never show in release,it just\nshow in `!bool.fromEnvironment(\"dart.vm.product\")` .\n```\nvoid setDebugViewBinderEnable({bool isEnable = !inProduction, ItemViewBinder? debugViewBinder})\n```\n\n# Screenshots\n\n## Chat Sample\n\n\u003cimg src=\"https://github.com/Wenlong-Guo/flutter_multitype/blob/master/example/screenshots/screenshots_03.jpg\" width=500/\u003e\n\n## Media Sample\n\n\u003cimg src=\"https://github.com/Wenlong-Guo/flutter_multitype/blob/master/example/screenshots/screenshots_02.jpg\" width=500/\u003e\n\n## Blog Sample\n\n\u003cimg src=\"https://github.com/Wenlong-Guo/flutter_multitype/blob/master/example/screenshots/screenshots_01.jpg\" width=500/\u003e\n\n# Thanks\n\n[MultiType](https://github.com/drakeet/MultiType)\n\n# 关于作者\n\nGitHub \u0026nbsp;: [Wenlong-Guo](https://github.com/Wenlong-Guo)  \nEmail \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;: guowenlong20000@sina.com   \nWeChat : xiaoguo9745\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenlong-guo%2Fflutter_multitype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwenlong-guo%2Fflutter_multitype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwenlong-guo%2Fflutter_multitype/lists"}