├── test └── adsorptionview_test.dart ├── android ├── local.properties └── app │ └── src │ └── main │ └── java │ └── io │ └── flutter │ └── plugins │ └── GeneratedPluginRegistrant.java ├── lib ├── adsorptiondatabin.dart └── adsorptionview_flutter.dart ├── .gitignore ├── CHANGELOG.md ├── example ├── adsorptionlistbin.dart └── example.dart ├── pubspec.yaml ├── pubspec.lock ├── README.md └── LICENSE /test/adsorptionview_test.dart: -------------------------------------------------------------------------------- 1 | 2 | void main() { 3 | 4 | } 5 | -------------------------------------------------------------------------------- /android/local.properties: -------------------------------------------------------------------------------- 1 | sdk.dir=D:\\Android_SDK 2 | flutter.sdk=E:\\Flutter\\flutter 3 | flutter.versionName=0.0.1 -------------------------------------------------------------------------------- /lib/adsorptiondatabin.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class AdsorptionData { 4 | bool isHeader = false; 5 | GlobalKey adsorptionKey = new GlobalKey(); 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | ios/.generated/ 9 | ios/Flutter/Generated.xcconfig 10 | ios/Runner/GeneratedPluginRegistrant.* 11 | 12 | .flutter-plugins 13 | .idea 14 | .metadata 15 | *.iml 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.1.3] - 2018.10.18 2 | 3 | * optimization and Non-equal height items are no longer supported 4 | 5 | ## [0.1.2] - 2018.10.18 6 | 7 | * Prevent IOS devices from springing 8 | 9 | ## [0.1.1] - 2018.10.15. 10 | 11 | * Describe initial release. 12 | -------------------------------------------------------------------------------- /example/adsorptionlistbin.dart: -------------------------------------------------------------------------------- 1 | import 'package:adsorptionview_flutter/adsorptiondatabin.dart'; 2 | 3 | class AdsorptionListBin extends AdsorptionData{ 4 | AdsorptionListBin( this.headerName); 5 | 6 | String headerName; 7 | 8 | @override 9 | String toString() { 10 | return 'AdsorptionListBin{headerName: $headerName}'; 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java: -------------------------------------------------------------------------------- 1 | package io.flutter.plugins; 2 | 3 | import io.flutter.plugin.common.PluginRegistry; 4 | 5 | /** 6 | * Generated file. Do not edit. 7 | */ 8 | public final class GeneratedPluginRegistrant { 9 | public static void registerWith(PluginRegistry registry) { 10 | if (alreadyRegisteredWith(registry)) { 11 | return; 12 | } 13 | } 14 | 15 | private static boolean alreadyRegisteredWith(PluginRegistry registry) { 16 | final String key = GeneratedPluginRegistrant.class.getCanonicalName(); 17 | if (registry.hasPlugin(key)) { 18 | return true; 19 | } 20 | registry.registrarFor(key); 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: adsorptionview_flutter 2 | description: ListView adsorption ceiling layout, support Equally high items and Unequally high items. 3 | version: 0.1.3 4 | author: baoolong 5 | homepage: https://github.com/baoolong/Adsorptionview 6 | 7 | environment: 8 | sdk: ">=2.0.0-dev.68.0 <3.0.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | 14 | dev_dependencies: 15 | flutter_test: 16 | sdk: flutter 17 | 18 | # For information on the generic Dart part of this file, see the 19 | # following page: https://www.dartlang.org/tools/pub/pubspec 20 | 21 | # The following section is specific to Flutter. 22 | flutter: 23 | 24 | # To add assets to your package, add an assets section, like this: 25 | # assets: 26 | # - images/a_dot_burr.jpeg 27 | # - images/a_dot_ham.jpeg 28 | # 29 | # For details regarding assets in packages, see 30 | # https://flutter.io/assets-and-images/#from-packages 31 | # 32 | # An image asset can refer to one or more resolution-specific "variants", see 33 | # https://flutter.io/assets-and-images/#resolution-aware. 34 | 35 | # To add custom fonts to your package, add a fonts section here, 36 | # in this "flutter" section. Each entry in this list should have a 37 | # "family" key with the font family name, and a "fonts" key with a 38 | # list giving the asset and other descriptors for the font. For 39 | # example: 40 | # fonts: 41 | # - family: Schyler 42 | # fonts: 43 | # - asset: fonts/Schyler-Regular.ttf 44 | # - asset: fonts/Schyler-Italic.ttf 45 | # style: italic 46 | # - family: Trajan Pro 47 | # fonts: 48 | # - asset: fonts/TrajanPro.ttf 49 | # - asset: fonts/TrajanPro_Bold.ttf 50 | # weight: 700 51 | # 52 | # For details regarding fonts in packages, see 53 | # https://flutter.io/custom-fonts/#from-packages 54 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://www.dartlang.org/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.flutter-io.cn" 9 | source: hosted 10 | version: "2.1.0" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.flutter-io.cn" 16 | source: hosted 17 | version: "1.0.4" 18 | charcode: 19 | dependency: transitive 20 | description: 21 | name: charcode 22 | url: "https://pub.flutter-io.cn" 23 | source: hosted 24 | version: "1.1.2" 25 | collection: 26 | dependency: transitive 27 | description: 28 | name: collection 29 | url: "https://pub.flutter-io.cn" 30 | source: hosted 31 | version: "1.14.11" 32 | flutter: 33 | dependency: "direct main" 34 | description: flutter 35 | source: sdk 36 | version: "0.0.0" 37 | flutter_test: 38 | dependency: "direct dev" 39 | description: flutter 40 | source: sdk 41 | version: "0.0.0" 42 | matcher: 43 | dependency: transitive 44 | description: 45 | name: matcher 46 | url: "https://pub.flutter-io.cn" 47 | source: hosted 48 | version: "0.12.5" 49 | meta: 50 | dependency: transitive 51 | description: 52 | name: meta 53 | url: "https://pub.flutter-io.cn" 54 | source: hosted 55 | version: "1.1.6" 56 | path: 57 | dependency: transitive 58 | description: 59 | name: path 60 | url: "https://pub.flutter-io.cn" 61 | source: hosted 62 | version: "1.6.2" 63 | pedantic: 64 | dependency: transitive 65 | description: 66 | name: pedantic 67 | url: "https://pub.flutter-io.cn" 68 | source: hosted 69 | version: "1.5.0" 70 | quiver: 71 | dependency: transitive 72 | description: 73 | name: quiver 74 | url: "https://pub.flutter-io.cn" 75 | source: hosted 76 | version: "2.0.2" 77 | sky_engine: 78 | dependency: transitive 79 | description: flutter 80 | source: sdk 81 | version: "0.0.99" 82 | source_span: 83 | dependency: transitive 84 | description: 85 | name: source_span 86 | url: "https://pub.flutter-io.cn" 87 | source: hosted 88 | version: "1.5.5" 89 | stack_trace: 90 | dependency: transitive 91 | description: 92 | name: stack_trace 93 | url: "https://pub.flutter-io.cn" 94 | source: hosted 95 | version: "1.9.3" 96 | stream_channel: 97 | dependency: transitive 98 | description: 99 | name: stream_channel 100 | url: "https://pub.flutter-io.cn" 101 | source: hosted 102 | version: "2.0.0" 103 | string_scanner: 104 | dependency: transitive 105 | description: 106 | name: string_scanner 107 | url: "https://pub.flutter-io.cn" 108 | source: hosted 109 | version: "1.0.4" 110 | term_glyph: 111 | dependency: transitive 112 | description: 113 | name: term_glyph 114 | url: "https://pub.flutter-io.cn" 115 | source: hosted 116 | version: "1.1.0" 117 | test_api: 118 | dependency: transitive 119 | description: 120 | name: test_api 121 | url: "https://pub.flutter-io.cn" 122 | source: hosted 123 | version: "0.2.4" 124 | typed_data: 125 | dependency: transitive 126 | description: 127 | name: typed_data 128 | url: "https://pub.flutter-io.cn" 129 | source: hosted 130 | version: "1.1.6" 131 | vector_math: 132 | dependency: transitive 133 | description: 134 | name: vector_math 135 | url: "https://pub.flutter-io.cn" 136 | source: hosted 137 | version: "2.0.8" 138 | sdks: 139 | dart: ">=2.2.0 <3.0.0" 140 | -------------------------------------------------------------------------------- /example/example.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/rendering.dart'; 3 | import 'package:adsorptionview_flutter/adsorptionview_flutter.dart'; 4 | import 'adsorptionlistbin.dart'; 5 | 6 | void main() => runApp( 7 | new MaterialApp( 8 | title: 'AdsorptionViewDemo', 9 | theme: new ThemeData( 10 | primaryColor: Colors.white, 11 | ), 12 | home: new AdsorptionViewDemo(), 13 | ) 14 | ); 15 | 16 | 17 | 18 | class AdsorptionViewDemo extends StatefulWidget{ 19 | @override 20 | State createState() { 21 | List adsorptionDatas=new List(); 22 | AdsorptionListBin adsorptionData; 23 | 24 | adsorptionData=new AdsorptionListBin("A"); 25 | adsorptionData.isHeader=true; 26 | adsorptionDatas.add(adsorptionData); 27 | 28 | adsorptionData=new AdsorptionListBin("阿杜"); 29 | adsorptionDatas.add(adsorptionData); 30 | 31 | adsorptionData=new AdsorptionListBin("阿宝"); 32 | adsorptionDatas.add(adsorptionData); 33 | 34 | adsorptionData=new AdsorptionListBin("艾夫杰尼"); 35 | adsorptionDatas.add(adsorptionData); 36 | 37 | adsorptionData=new AdsorptionListBin("阿牛"); 38 | adsorptionDatas.add(adsorptionData); 39 | 40 | adsorptionData=new AdsorptionListBin("安苏羽"); 41 | adsorptionDatas.add(adsorptionData); 42 | 43 | adsorptionData=new AdsorptionListBin("阿勒长青"); 44 | adsorptionDatas.add(adsorptionData); 45 | 46 | 47 | adsorptionData=new AdsorptionListBin("B"); 48 | adsorptionData.isHeader=true; 49 | adsorptionDatas.add(adsorptionData); 50 | 51 | adsorptionData=new AdsorptionListBin("白小白"); 52 | adsorptionDatas.add(adsorptionData); 53 | 54 | adsorptionData=new AdsorptionListBin("白羽毛"); 55 | adsorptionDatas.add(adsorptionData); 56 | 57 | adsorptionData=new AdsorptionListBin("Bridge"); 58 | adsorptionDatas.add(adsorptionData); 59 | 60 | adsorptionData=new AdsorptionListBin("斑马"); 61 | adsorptionDatas.add(adsorptionData); 62 | 63 | adsorptionData=new AdsorptionListBin("白一阳"); 64 | adsorptionDatas.add(adsorptionData); 65 | 66 | adsorptionData=new AdsorptionListBin("白举纲"); 67 | adsorptionDatas.add(adsorptionData); 68 | 69 | adsorptionData=new AdsorptionListBin("暴林"); 70 | adsorptionDatas.add(adsorptionData); 71 | 72 | 73 | adsorptionData=new AdsorptionListBin("C"); 74 | adsorptionData.isHeader=true; 75 | adsorptionDatas.add(adsorptionData); 76 | 77 | adsorptionData=new AdsorptionListBin("陈奕迅"); 78 | adsorptionDatas.add(adsorptionData); 79 | 80 | adsorptionData=new AdsorptionListBin("陈小春"); 81 | adsorptionDatas.add(adsorptionData); 82 | 83 | adsorptionData=new AdsorptionListBin("成龙"); 84 | adsorptionDatas.add(adsorptionData); 85 | 86 | adsorptionData=new AdsorptionListBin("陈百强"); 87 | adsorptionDatas.add(adsorptionData); 88 | 89 | adsorptionData=new AdsorptionListBin("迟志强"); 90 | adsorptionDatas.add(adsorptionData); 91 | 92 | adsorptionData=new AdsorptionListBin("崔健"); 93 | adsorptionDatas.add(adsorptionData); 94 | 95 | adsorptionData=new AdsorptionListBin("陈晓东"); 96 | adsorptionDatas.add(adsorptionData); 97 | 98 | adsorptionData=new AdsorptionListBin("陈学冬"); 99 | adsorptionDatas.add(adsorptionData); 100 | 101 | adsorptionData=new AdsorptionListBin("蔡国庆"); 102 | adsorptionDatas.add(adsorptionData); 103 | 104 | adsorptionData=new AdsorptionListBin("陈冠希"); 105 | adsorptionDatas.add(adsorptionData); 106 | 107 | adsorptionData=new AdsorptionListBin("陈琳"); 108 | adsorptionDatas.add(adsorptionData); 109 | return new AdsorptionViewState(adsorptionDatas); 110 | } 111 | } 112 | 113 | ///此控件适用于固定高度的ListView 114 | class AdsorptionViewState extends State{ 115 | 116 | AdsorptionViewState(this.adsorptionDatas); 117 | 118 | List adsorptionDatas; 119 | double itemHeight=50.0; 120 | 121 | 122 | @override 123 | Widget build(BuildContext context) { 124 | return new Scaffold( 125 | appBar: new AppBar( 126 | title: new Text("吸附布局"), 127 | ), 128 | body:new AdsorptionView( 129 | adsorptionDatas: adsorptionDatas, 130 | generalItemChild: (AdsorptionListBin bin) { 131 | return new Container( 132 | alignment: Alignment.centerLeft, 133 | margin: EdgeInsets.fromLTRB(15.0, 0.0, 0.0, 0.0), 134 | child: new Text( 135 | bin.headerName, 136 | style: new TextStyle(fontSize: 18.0, color: Colors.grey), 137 | ), 138 | ); 139 | }, 140 | headChild: (AdsorptionListBin bin) { 141 | return new Container( 142 | color: Colors.grey, 143 | alignment: Alignment.centerLeft, 144 | padding: EdgeInsets.fromLTRB(15.0, 0.0, 0.0, 0.0), 145 | child: new Text( 146 | bin.headerName, 147 | style: new TextStyle( fontSize: 20.0,color: Colors.black), 148 | ), 149 | ); 150 | }, 151 | ), 152 | ); 153 | } 154 | 155 | } -------------------------------------------------------------------------------- /lib/adsorptionview_flutter.dart: -------------------------------------------------------------------------------- 1 | import 'package:adsorptionview_flutter/adsorptiondatabin.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter/rendering.dart'; 4 | 5 | typedef Widget GetHearWidget (M bin); 6 | typedef Widget GetGeneralItem (M bin); 7 | 8 | class AdsorptionView extends StatefulWidget{ 9 | 10 | final List adsorptionDatas; 11 | final GetHearWidget headChild; 12 | final GetGeneralItem generalItemChild; 13 | final double itemHeight; 14 | final double itemWidth; 15 | final double cacheExtent; 16 | 17 | AdsorptionView({ 18 | @required this.adsorptionDatas, 19 | @required this.headChild, 20 | @required this.generalItemChild, 21 | this.itemHeight:50.0, 22 | this.itemWidth:double.infinity, 23 | this.cacheExtent:30.0, 24 | }): assert( 25 | adsorptionDatas!=null, 26 | generalItemChild!=null&& 27 | headChild!=null, 28 | ); 29 | 30 | @override 31 | State createState() { 32 | return new AdsorptionViewState(); 33 | } 34 | } 35 | 36 | ///此控件适用于固定高度的ListView 37 | class AdsorptionViewState extends State>{ 38 | 39 | ScrollController scrollController=new ScrollController(); 40 | 41 | @override 42 | Widget build(BuildContext context) { 43 | return new Stack( 44 | children: [ 45 | new AdsorptionListView( 46 | scrollController: scrollController, 47 | adsorptionDatas: widget.adsorptionDatas, 48 | generalItemChild: widget.generalItemChild, 49 | headChild: widget.headChild, 50 | itemHeight: widget.itemHeight, 51 | itemWidth: widget.itemWidth, 52 | cacheExtent: widget.cacheExtent, 53 | ), 54 | new GestureDetector( 55 | onTap: (){ 56 | double pixels= scrollController.position.pixels; 57 | int a=pixels~/widget.itemHeight; 58 | for(int i=a;i>=0;i--){ 59 | if(widget.adsorptionDatas[i].isHeader) { 60 | scrollController.animateTo(i*widget.itemHeight, duration: new Duration(milliseconds: 200), curve: Curves.linear); 61 | break; 62 | } 63 | } 64 | }, 65 | child: new HeaderView( 66 | scrollController: scrollController, 67 | headChild: widget.headChild, 68 | adsorptionDatas: widget.adsorptionDatas, 69 | itemWidth: widget.itemWidth, 70 | itemHeight: widget.itemHeight, 71 | ), 72 | ), 73 | ], 74 | ); 75 | } 76 | } 77 | 78 | 79 | class AdsorptionListView extends StatefulWidget{ 80 | final ScrollController scrollController; 81 | final double itemHeight; 82 | final double itemWidth; 83 | final double cacheExtent; 84 | final List adsorptionDatas; 85 | final GetHearWidget headChild; 86 | final GetGeneralItem generalItemChild; 87 | 88 | AdsorptionListView({ 89 | @required this.adsorptionDatas, 90 | @required this.headChild, 91 | @required this.generalItemChild, 92 | this.itemHeight:50.0, 93 | this.itemWidth:double.infinity, 94 | this.cacheExtent:30.0, 95 | @required this.scrollController, 96 | }): assert( 97 | adsorptionDatas!=null, 98 | generalItemChild!=null&& 99 | headChild!=null, 100 | ); 101 | 102 | @override 103 | State createState() { 104 | return AdsorptionListViewState(); 105 | } 106 | } 107 | 108 | class AdsorptionListViewState extends State>{ 109 | 110 | ScrollPhysics scrollPhysics=new ClampingScrollPhysics(); 111 | 112 | @override 113 | Widget build(BuildContext context) { 114 | return new ListView.builder( 115 | physics: scrollPhysics, 116 | cacheExtent: widget.cacheExtent, 117 | controller: widget.scrollController, 118 | itemCount: widget.adsorptionDatas.length, 119 | itemBuilder: (context, index) { 120 | if(widget.adsorptionDatas[index].isHeader){ 121 | return new Container( 122 | width: widget.itemWidth, 123 | height: widget.itemHeight, 124 | child: widget.headChild(widget.adsorptionDatas[index]), 125 | ); 126 | }else{ 127 | return new Container( 128 | width: widget.itemWidth, 129 | height: widget.itemHeight, 130 | child: widget.generalItemChild(widget.adsorptionDatas[index]), 131 | ); 132 | } 133 | }, 134 | ); 135 | } 136 | } 137 | 138 | 139 | class HeaderView extends StatefulWidget{ 140 | 141 | final ScrollController scrollController; 142 | final double itemHeight; 143 | final double itemWidth; 144 | final GetHearWidget headChild; 145 | final List adsorptionDatas; 146 | 147 | HeaderView({ 148 | @required this.scrollController, 149 | this.itemHeight:50.0, 150 | this.itemWidth:double.infinity, 151 | @required this.headChild, 152 | @required this.adsorptionDatas, 153 | }); 154 | 155 | @override 156 | State createState() { 157 | return new HeaderViewState(); 158 | } 159 | } 160 | 161 | class HeaderViewState extends State>{ 162 | double headerOffset=0.0; 163 | T headerStr; 164 | double beforeScroll=0.0; 165 | 166 | @override 167 | void initState() { 168 | headerStr=widget.adsorptionDatas.first; 169 | 170 | widget.scrollController.addListener((){ 171 | //计算滑动了多少距离了 172 | double pixels=widget.scrollController.position.pixels; 173 | 174 | //根据滑动的距离 计算当前可见的第一个Item的Position 175 | int a=pixels~/widget.itemHeight; 176 | //计算滑动出屏幕多少距离 177 | double b=pixels%widget.itemHeight; 178 | double currentScrollPosition=widget.scrollController.position.extentBefore; 179 | //如果下一个item是Header 则偏移 如果不是 则偏移量=0 180 | if(widget.adsorptionDatas[a+1].isHeader){ 181 | setState(() { 182 | // 改变布局 183 | if(currentScrollPosition-beforeScroll<0){ 184 | //检测到再向上划就越出当前组 提前改变header的内容并偏移 185 | for(int i=a;i>=0;i--){ 186 | if(widget.adsorptionDatas[i].isHeader){ 187 | headerStr=widget.adsorptionDatas[i]; 188 | break; 189 | } 190 | } 191 | } 192 | beforeScroll=currentScrollPosition; 193 | headerOffset=-b; 194 | }); 195 | }else{ 196 | //始终使header处于完整显示状态 197 | for(int i=a;i>=0;i--){ 198 | if(widget.adsorptionDatas[i].isHeader) { 199 | if(headerStr != widget.adsorptionDatas[i]) { 200 | setState(() { 201 | headerStr = widget.adsorptionDatas[i]; 202 | }); 203 | } 204 | break; 205 | } 206 | } 207 | if(headerOffset!=0){ 208 | setState(() { 209 | headerOffset=0.0; 210 | }); 211 | } 212 | } 213 | }); 214 | super.initState(); 215 | } 216 | 217 | @override 218 | Widget build(BuildContext context) { 219 | return new Container( 220 | transform: Matrix4.translationValues(0.0, headerOffset, 0.0), 221 | width: widget.itemWidth, 222 | height: widget.itemHeight, 223 | child: widget.headChild(headerStr), 224 | ); 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # adsorptionview 2 | 3 | [![pub package](https://img.shields.io/pub/v/adsorptionview_flutter.svg)](https://pub.dartlang.org/packages/adsorptionview_flutter) 4 | 5 | ListView adsorption ceiling layout, only support Equally high items. 6 | 7 | ListView的吸顶布局,现在仅支持等高的Item。 8 | 9 | HomePage:[https://github.com/baoolong/Adsorptionview](https://github.com/baoolong/Adsorptionview) 10 | 11 | MoreWidght:[https://github.com/OpenFlutter/PullToRefresh](https://github.com/OpenFlutter/PullToRefresh) 12 | 13 | 14 | 15 | ## Usage 16 | 17 | Add this to your package's pubspec.yaml file: 18 | 19 | dependencies: 20 | adsorptionview_flutter: ^0.1.3 21 | 22 | Add it to your dart file: 23 | 24 | import 'package:adsorptionview_flutter/adsorptionview_flutter.dart'; 25 | 26 | And ListView dataBin must extends AdsorptionData ,Add it to your dataBin file 27 | 28 | import 'package:adsorptionview_flutter/adsorptiondatabin.dart'; 29 | 30 | ## Example 31 | 32 | #### Bin 33 | 34 | import 'package:adsorptionview_flutter/adsorptiondatabin.dart'; 35 | 36 | class AdsorptionListBin extends AdsorptionData{ 37 | AdsorptionListBin( this.headerName); 38 | 39 | String headerName; 40 | 41 | @override 42 | String toString() { 43 | return 'AdsorptionListBin{headerName: $headerName}'; 44 | } 45 | 46 | } 47 | 48 | 49 | #### Demo 50 | import 'package:flutter/material.dart'; 51 | import 'package:flutter/rendering.dart'; 52 | import 'package:flutterapp/bin/adsorptionlistbin.dart'; 53 | import 'package:adsorptionview_flutter/adsorptionview_flutter.dart'; 54 | 55 | class AdsorptionViewDemo extends StatefulWidget{ 56 | @override 57 | State createState() { 58 | List adsorptionDatas=new List(); 59 | AdsorptionListBin adsorptionData; 60 | 61 | adsorptionData=new AdsorptionListBin("A"); 62 | adsorptionData.isHeader=true; 63 | adsorptionDatas.add(adsorptionData); 64 | 65 | adsorptionData=new AdsorptionListBin("阿杜"); 66 | adsorptionDatas.add(adsorptionData); 67 | 68 | adsorptionData=new AdsorptionListBin("阿宝"); 69 | adsorptionDatas.add(adsorptionData); 70 | 71 | adsorptionData=new AdsorptionListBin("艾夫杰尼"); 72 | adsorptionDatas.add(adsorptionData); 73 | 74 | adsorptionData=new AdsorptionListBin("阿牛"); 75 | adsorptionDatas.add(adsorptionData); 76 | 77 | adsorptionData=new AdsorptionListBin("安苏羽"); 78 | adsorptionDatas.add(adsorptionData); 79 | 80 | adsorptionData=new AdsorptionListBin("阿勒长青"); 81 | adsorptionDatas.add(adsorptionData); 82 | 83 | 84 | adsorptionData=new AdsorptionListBin("B"); 85 | adsorptionData.isHeader=true; 86 | adsorptionDatas.add(adsorptionData); 87 | 88 | adsorptionData=new AdsorptionListBin("白小白"); 89 | adsorptionDatas.add(adsorptionData); 90 | 91 | adsorptionData=new AdsorptionListBin("白羽毛"); 92 | adsorptionDatas.add(adsorptionData); 93 | 94 | adsorptionData=new AdsorptionListBin("Bridge"); 95 | adsorptionDatas.add(adsorptionData); 96 | 97 | adsorptionData=new AdsorptionListBin("斑马"); 98 | adsorptionDatas.add(adsorptionData); 99 | 100 | adsorptionData=new AdsorptionListBin("白一阳"); 101 | adsorptionDatas.add(adsorptionData); 102 | 103 | adsorptionData=new AdsorptionListBin("白举纲"); 104 | adsorptionDatas.add(adsorptionData); 105 | 106 | adsorptionData=new AdsorptionListBin("暴林"); 107 | adsorptionDatas.add(adsorptionData); 108 | 109 | 110 | adsorptionData=new AdsorptionListBin("C"); 111 | adsorptionData.isHeader=true; 112 | adsorptionDatas.add(adsorptionData); 113 | 114 | adsorptionData=new AdsorptionListBin("陈奕迅"); 115 | adsorptionDatas.add(adsorptionData); 116 | 117 | adsorptionData=new AdsorptionListBin("陈小春"); 118 | adsorptionDatas.add(adsorptionData); 119 | 120 | adsorptionData=new AdsorptionListBin("成龙"); 121 | adsorptionDatas.add(adsorptionData); 122 | 123 | adsorptionData=new AdsorptionListBin("陈百强"); 124 | adsorptionDatas.add(adsorptionData); 125 | 126 | adsorptionData=new AdsorptionListBin("迟志强"); 127 | adsorptionDatas.add(adsorptionData); 128 | 129 | adsorptionData=new AdsorptionListBin("崔健"); 130 | adsorptionDatas.add(adsorptionData); 131 | 132 | adsorptionData=new AdsorptionListBin("陈晓东"); 133 | adsorptionDatas.add(adsorptionData); 134 | 135 | adsorptionData=new AdsorptionListBin("陈学冬"); 136 | adsorptionDatas.add(adsorptionData); 137 | 138 | adsorptionData=new AdsorptionListBin("蔡国庆"); 139 | adsorptionDatas.add(adsorptionData); 140 | 141 | adsorptionData=new AdsorptionListBin("陈冠希"); 142 | adsorptionDatas.add(adsorptionData); 143 | 144 | adsorptionData=new AdsorptionListBin("陈琳"); 145 | adsorptionDatas.add(adsorptionData); 146 | return new AdsorptionViewState(adsorptionDatas); 147 | } 148 | } 149 | 150 | ///此控件适用于固定高度的ListView 151 | class AdsorptionViewState extends State{ 152 | 153 | AdsorptionViewState(this.adsorptionDatas); 154 | 155 | List adsorptionDatas; 156 | double itemHeight=50.0; 157 | 158 | 159 | @override 160 | Widget build(BuildContext context) { 161 | return new Scaffold( 162 | appBar: new AppBar( 163 | title: new Text("吸附布局"), 164 | ), 165 | body:new AdsorptionView( 166 | adsorptionDatas: adsorptionDatas, 167 | generalItemChild: (AdsorptionListBin bin) { 168 | return new Container( 169 | alignment: Alignment.centerLeft, 170 | margin: EdgeInsets.fromLTRB(15.0, 0.0, 0.0, 0.0), 171 | child: new Text( 172 | bin.headerName, 173 | style: new TextStyle(fontSize: 18.0, color: Colors.grey), 174 | ), 175 | ); 176 | }, 177 | headChild: (AdsorptionListBin bin) { 178 | return new Container( 179 | color: Colors.grey, 180 | alignment: Alignment.centerLeft, 181 | padding: EdgeInsets.fromLTRB(15.0, 0.0, 0.0, 0.0), 182 | child: new Text( 183 | bin.headerName, 184 | style: new TextStyle( fontSize: 20.0,color: Colors.black), 185 | ), 186 | ); 187 | }, 188 | ), 189 | ); 190 | } 191 | } 192 | 193 | ## Notice 194 | 195 | 吸顶布局不能使用类似苹果的弹簧布局,以后可能会支持;目前等高的支持比较好,非等高的有点问题,后续会改进 196 | 197 | Adsorptionview ceiling layout can not use the spring layout of Apple, may be supported in the future; the current support of the equally hight items better, the unequally hight items has a problem, the follow-up will improve 198 | 199 | ## LICENSE 200 | MIT License 201 | 202 | Copyright (c) 2018 baoolong 203 | 204 | Permission is hereby granted, free of charge, to any person obtaining a copy 205 | of this software and associated documentation files (the "Software"), to deal 206 | in the Software without restriction, including without limitation the rights 207 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 208 | copies of the Software, and to permit persons to whom the Software is 209 | furnished to do so, subject to the following conditions: 210 | 211 | The above copyright notice and this permission notice shall be included in all 212 | copies or substantial portions of the Software. 213 | 214 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 215 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 216 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 217 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 218 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 219 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 220 | SOFTWARE. 221 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------