如何在Flutter中对小部件进行排序

在这里,我想列出一些项目,并按照ID或等级对它们进行排序。当我单击侧面抽屉按钮时,将需要使用已排序的项目重新排列列表视图,希望您理解我的问题。

I've tried this smooth_sort package for sorting but it won't work for me because it will sort based on the index. and I want to sort based on my own value.

Here is the output image enter image description here

这是我的代码

class _MapAddressListingScreenState extends State<MapAddressListingScreen>
    with AfterLayoutMixin<MapAddressListingScreen> {
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  List addressData;

  @override
  void afterFirstLayout(BuildContext context) {
    _getAddress();
  }

  _getAddress() {
    List requestedLatlong = ModalRoute.of(context).settings.arguments;

    print("============================Address Data");
    print(requestedLatlong);
    setState(() {
      addressData = requestedLatlong;
    });
  }

  List<Widget> _addressData() {
    List<Widget> _address = [];
    for (int i = 0; i < addressData.length; i++) {
      _address.add(
        GestureDetector(
          onTap: () {
            print('address list taped');
            AddWalkinModel model = widget.addWalkinModel;
            print("After model");
            model.fromMap = false;
            model.fromMapListing = true;
            model.autoAssign = addressData[i]['autoAssign'];
            model.branchId = addressData[i]['branchId'];
            model.branchServiceId = addressData[i]['branchServiceId'];
            print("After Model Model");
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => DynamicScreen(
                  addWalkinModel: model,
                ),
              ),
            );
          },
          child: AddressListingTile(listingTileData: addressData[i]),
        ),
      );
    }
    return _address;
  }

  Widget itemCard() {
    return Container(
      child: Column(
        children: _addressData(),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    var colorStyles = Theming.colorstyle(context);
    return Scaffold(
      key: _scaffoldKey,
      backgroundColor: colorStyles['primary'],
      appBar: AppBar(
        title: Text("BSP Listview "),
        centerTitle: true,
        elevation: 0,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.sort),
            onPressed: () {
              _scaffoldKey.currentState.openEndDrawer();
            },
          ),
        ],
      ),
      endDrawer: BspFilterScreen(),
      body: Stack(
        children: <Widget>[
          Container(
            child: ClipRRect(
              borderRadius: new BorderRadius.only(
                  topLeft: const Radius.circular(30.0),
                  topRight: const Radius.circular(30.0)),
              child: Stack(
                children: <Widget>[
                  SingleChildScrollView(
                    child: Container(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          itemCard(),
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
评论