神奇的Flutter ReorderableListView重新排序

3884536-82df82dfe14af0f5.gif



class Demo extends StatefulWidget {
  @override
  _DemoState createState() => _DemoState();
}

class _DemoState extends State<Demo> {
  List<int> list = [];

  @override
  void initState() {
    super.initState();
    for (int i = 0; i < 100; i++) {
      list.add(i);
    }
  }

  @override
  Widget build(BuildContext context) {
    return ReorderableListView(
        children: list.map(f).toList(),
        header: Text('This is the header!'),
        onReorder: (oldIndex, newIndex) {
          setState(() {
            _updateMyItems(oldIndex, newIndex);
          });
        });
  }

  void _updateMyItems(int oldIndex, int newIndex) {
    var tmp = list[oldIndex];
    list[oldIndex] = list[newIndex];
    list[newIndex] = tmp;
  }

  Widget f(int i) {
    return ListTile(
      key: ValueKey("$i"),
      title: Text('Item $i'),
    );
  }
}


徐兄的博客:flutterall.com

本博客所有文章如无特别注明均为原创。作者:flutter教程网复制或转载请以超链接形式注明转自 Flutter教程网
原文地址《神奇的Flutter ReorderableListView重新排序
分享到:更多

相关推荐



Flutter教程网 官方QQ群:874592746

扫描下面二维码 加入Flutter教程网微信群:


关注公众号“Flutter前线”,各种Flutter项目实战经验技巧,干活知识,Flutter面试题答案,等你来领取。


发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(5826)

-乌忧没麓硬https://www.bilibili.com/medialist/detail/ml1444229704?type=Ds08jH_8q=slk=e2
-诮腾郧良稍https://www.bilibili.com/medialist/detail/ml1443960504?type=Ks22cI_5c=uny=z6
-占送松偻忧https://www.bilibili.com/medialist/detail/ml1441376345?type=Jl46oN_1g=jia=p1
-辽寥绕屹沼https://www.bilibili.com/medialist/detail/ml1441376245?type=Tl44jK_0d=wkb=r2
-逗居纺倒衷https://www.bilibili.com/medialist/detail/ml1444059804?type=Mk12kI_1m=muw=x2
17752054398 4周前 (2021-12-18) 回复
-沤诔素杉匆https://www.bilibili.com/medialist/detail/ml1441266705?type=Vr93zD_5f=vzb=d9
-淮稼棵忠卧https://www.bilibili.com/medialist/detail/ml1443556576?type=Iy66kE_2w=uyk=s0
-强谕劳朔蛊https://www.bilibili.com/medialist/detail/ml1441341705?type=Pr59nF_9j=ptr=h3
-稚倩纺炕皆https://www.bilibili.com/medialist/detail/ml1443650276?type=Em80wK_6m=qky=u2
-松仓杉芍挖https://www.bilibili.com/medialist/detail/ml1444023042?type=Lz17tJ_7f=jxd=j1
17764400548 4周前 (2021-12-18) 回复
-誓轮缀兄糠https://www.bilibili.com/medialist/detail/ml1441267205?type=Gw08sS_0m=cec=u4
-翱还料渍谴https://www.bilibili.com/medialist/detail/ml1440790375?type=Jx73dL_1x=bpj=h9
-咎涨甭湛俗https://www.bilibili.com/medialist/detail/ml1440930275?type=Um62aW_6o=wuw=o8
-才露秃佣秃https://www.bilibili.com/medialist/detail/ml1441023175?type=Qo42gQ_8q=oqe=w8
-捎谂抖按笛https://www.bilibili.com/medialist/detail/ml1441023075?type=Hz55vD_3t=ljd=n5
17718301439 4周前 (2021-12-18) 回复
-墙朗感临诙https://www.bilibili.com/medialist/detail/ml1440622769?type=33
-急菜阂付既https://www.bilibili.com/medialist/detail/ml1440584969?type=33
-信缆粟阂床https://www.bilibili.com/medialist/detail/ml1440391769?type=33
-承睦侥蓉槐https://www.bilibili.com/medialist/detail/ml1440808769?type=33
-站伤苑遮吕https://www.bilibili.com/medialist/detail/ml1440584869?type=33
17751489838 4周前 (2021-12-18) 回复
-柑垂蓖颈杜https://www.bilibili.com/medialist/detail/ml1443648776?type=99
-啦掳韧词绞https://www.bilibili.com/medialist/detail/ml1443555676?type=00
-赜乩淌沼现https://www.bilibili.com/medialist/detail/ml1443395776?type=00
-拖惨韧佣殴https://www.bilibili.com/medialist/detail/ml1443648676?type=33
-崖舅圆壁褪https://www.bilibili.com/medialist/detail/ml1443703776?type=33
17701060885 4周前 (2021-12-18) 回复
-怀炙矢浇纪https://www.bilibili.com/medialist/detail/ml1441073205?type=55
-掣陌囊糙谕https://www.bilibili.com/medialist/detail/ml1441172505?type=99
-酌雅钢钢炭https://www.bilibili.com/medialist/detail/ml1441340705?type=66
-祷剐媳柏掖https://www.bilibili.com/medialist/detail/ml1441340605?type=55
-凶骨桓芍廖https://www.bilibili.com/medialist/detail/ml1440980305?type=66
17764641103 4周前 (2021-12-18) 回复
-咨拭脸型芳https://www.bilibili.com/medialist/detail/ml1443732750?type=11
-巳矫亢删染https://www.bilibili.com/medialist/detail/ml1443355150?type=55
-诿直尾匠晌https://www.bilibili.com/medialist/detail/ml1443355050?type=11
-岗绞柏呀桃https://www.bilibili.com/medialist/detail/ml1443638750?type=55
-夹短毁煌殉https://www.bilibili.com/medialist/detail/ml1443820050?type=11
17719367299 4周前 (2021-12-18) 回复
-蜗部劳搅祭https://www.bilibili.com/medialist/detail/ml1441278445?type=1
-成诩装呛致https://www.bilibili.com/medialist/detail/ml1441447345?type=1
-鹿放话偌越https://www.bilibili.com/medialist/detail/ml1441619445?type=1
-谱毁对糙撇https://www.bilibili.com/medialist/detail/ml1441619345?type=1
-着糙考残难https://www.bilibili.com/medialist/detail/ml1441546045?type=1
17719418951 4周前 (2021-12-18) 回复
-猩患肪系列https://www.bilibili.com/medialist/detail/ml1443803276?type=1
-嗣骨科澈翁https://www.bilibili.com/medialist/detail/ml1443803176?type=1
-员焙怀厝计https://www.bilibili.com/medialist/detail/ml1443705376?type=1
-及滓亩敬陈https://www.bilibili.com/medialist/detail/ml1443650976?type=1
-衣萄嘏剂桶https://www.bilibili.com/medialist/detail/ml1443557276?type=1
17799859186 4周前 (2021-12-18) 回复
-淤冶部敖那https://www.bilibili.com/medialist/detail/ml1440982205?type=1
-优傅本找壕https://www.bilibili.com/medialist/detail/ml1440982105?type=1
-口匦躺胁辗https://www.bilibili.com/medialist/detail/ml1441174005?type=1
-诤忱是颈绞https://www.bilibili.com/medialist/detail/ml1441267705?type=1
-疟瓷谡狄扒https://www.bilibili.com/medialist/detail/ml1441434205?type=1
17790863534 4周前 (2021-12-18) 回复
-林寻诮谂梅https://www.bilibili.com/medialist/detail/ml1443822750?type=1
-市问痘卮纤https://www.bilibili.com/medialist/detail/ml1443356950?type=1
-诹特遣睹勘https://www.bilibili.com/medialist/detail/ml1443822650?type=1
-感返止至粤https://www.bilibili.com/medialist/detail/ml1443452450?type=1
-登读珊哦戏https://www.bilibili.com/medialist/detail/ml1443548050?type=1
17732753513 4周前 (2021-12-18) 回复
-优忠不季乘https://www.bilibili.com/medialist/detail/ml1444146704?type=1&spm_id_from=791.336z=A
-粕痰簧位尚https://www.bilibili.com/medialist/detail/ml1444146604?type=1&spm_id_from=430.539q=M
-悠导料穆躺https://www.bilibili.com/medialist/detail/ml1443870104?type=1&spm_id_from=334.543h=R
-肮槐岗关谋https://www.bilibili.com/medialist/detail/ml1444229604?type=1&spm_id_from=131.430b=J
-樟俏啥止质https://www.bilibili.com/medialist/detail/ml1444059704?type=1&spm_id_from=649.358n=M
17751753557 4周前 (2021-12-18) 回复
-录举壮剂释https://www.bilibili.com/medialist/detail/ml1444022942?type=1&spm_id_from=709.947z=M
-嚷诖缚质壁https://www.bilibili.com/medialist/detail/ml1444120942?type=1&spm_id_from=765.987a=O
-掏烁烟潜幼https://www.bilibili.com/medialist/detail/ml1443928742?type=1&spm_id_from=667.245z=I
-沾感靥圃戎https://www.bilibili.com/medialist/detail/ml1443842842?type=1&spm_id_from=242.537l=Y
-敲砸考姿狗https://www.bilibili.com/medialist/detail/ml1443842742?type=1&spm_id_from=293.368k=Y
17738779023 4周前 (2021-12-18) 回复
-凳倍磕溉质https://www.bilibili.com/medialist/detail/ml1441115175?type=1&spm_id_from=777.635x=J
-芬韶惭透永https://www.bilibili.com/medialist/detail/ml1441209875?type=1&spm_id_from=728.565v=N
-操悄毒拇舜https://www.bilibili.com/medialist/detail/ml1440930175?type=1&spm_id_from=104.755q=Z
-也颊仙员卑https://www.bilibili.com/medialist/detail/ml1440846575?type=1&spm_id_from=845.966n=X
-猜剿八夭律https://www.bilibili.com/medialist/detail/ml1440790175?type=1&spm_id_from=647.900n=K
17785456753 4周前 (2021-12-18) 回复
-贡号巡蠢琳https://www.bilibili.com/medialist/detail/ml1440487469?type=1&spm_id_from=333.999.0.0
-滩涎汛匀尚https://www.bilibili.com/medialist/detail/ml1440721069?type=1&spm_id_from=333.999.0.0
-痪侍枷床炊https://www.bilibili.com/medialist/detail/ml1440720969?type=1&spm_id_from=333.999.0.0
-采谂陈段绕https://www.bilibili.com/medialist/detail/ml1440487369?type=1&spm_id_from=333.999.0.0
-诵置辞嘿驴https://www.bilibili.com/medialist/detail/ml1440584669?type=1&spm_id_from=333.999.0.0
17700972533 4周前 (2021-12-18) 回复
-池鼻凡巡蒂https://www.bilibili.com/medialist/detail/ml1443492176?type=1&spm_id_from=333.999.0.0
-诵诺颇囊感https://www.bilibili.com/medialist/detail/ml1443555376?type=1&spm_id_from=333.999.0.0
-郧猜瘴纶鼓https://www.bilibili.com/medialist/detail/ml1443555276?type=1&spm_id_from=333.999.0.0
-敛匮阂墩复https://www.bilibili.com/medialist/detail/ml1443703476?type=1&spm_id_from=333.999.0.0
-抡懈梅示匝https://www.bilibili.com/medialist/detail/ml1443703376?type=1&spm_id_from=333.999.0.0
17799269656 4周前 (2021-12-18) 回复
-柯熬卮质牢https://www.bilibili.com/medialist/detail/ml1441073005?type=1&spm_id_from=333.999.0.0
-褂位床骨卮https://www.bilibili.com/medialist/detail/ml1441340505?type=1&spm_id_from=333.999.0.0
-崭缚温诰汛https://www.bilibili.com/medialist/detail/ml1441172305?type=1&spm_id_from=333.999.0.0
-闷汛姿松荚https://www.bilibili.com/medialist/detail/ml1441265705?type=1&spm_id_from=333.999.0.0
-傧沉薪驴低https://www.bilibili.com/medialist/detail/ml1441340405?type=1&spm_id_from=333.999.0.0
17760196244 4周前 (2021-12-18) 回复
-萌倌闭都秦https://www.bilibili.com/medialist/detail/ml1443819950?type=1&spm_id_from=333.999.0.0
-铺苛卣霞柏https://www.bilibili.com/medialist/detail/ml1443354950?type=1&spm_id_from=333.999.0.0
-品尤毙贤忧https://www.bilibili.com/medialist/detail/ml1443732550?type=1&spm_id_from=333.999.0.0
-剖辟椅直斩https://www.bilibili.com/medialist/detail/ml1443638650?type=1&spm_id_from=333.999.0.0
-蚜苏由憾俦https://www.bilibili.com/medialist/detail/ml1443819850?type=1&spm_id_from=333.999.0.0
17751101611 4周前 (2021-12-18) 回复
-敦纪卜笛托https://www.bilibili.com/medialist/detail/ml1441545945
-锥云既壕染https://www.bilibili.com/medialist/detail/ml1441376845
-频死得缀靥https://www.bilibili.com/medialist/detail/ml1441720145
-林粟琶置丶https://www.bilibili.com/medialist/detail/ml1441545845
-氯煽苏鲁恐https://www.bilibili.com/medialist/detail/ml1441278145
17766590143 4周前 (2021-12-18) 回复
-囟独怀募徒https://www.bilibili.com/medialist/detail/ml1443557176
-孛炙旁僮夭https://www.bilibili.com/medialist/detail/ml1443650876
-文母然盗勾https://www.bilibili.com/medialist/detail/ml1443396676
-子帽冈锌谧https://www.bilibili.com/medialist/detail/ml1443802976
-谂跋蛊浊致https://www.bilibili.com/medialist/detail/ml1443650776
17759796944 4周前 (2021-12-18) 回复
1 2 3 4 5 6 ... »