original text
https://medium.com/flutterdevs/explore-multi-select-items-in-flutter-a90665e17be
reference resources
- https://pub.dev/packages/multi_select_item
text
The fluent widget is built using a modern framework. It's like a reaction. Here, we start with widgets to create any application. Each component in the screen is a widget. This widget describes what his prospects should be based on his current configuration and state. The widget shows ideas similar to it and the current settings and status.
Fluent automated testing enables you to meet the high responsiveness of your application because it helps to find bug s and problems in your application. Fluent is a tool for developing mobile, desktop, web applications and code & a free and open source tool. Flutter has the ability to easily test any application. This ability is that they work the way we want on the target platform. Dart test is applicable to unit test and non ui test; It runs on the development machine and does not rely on the GUI of the fluent application.
In this blog, we will explore the Flutter multi choice project. We will also implement a demonstration of multi project selection in fluent. How to use them in your Flutter application. So let's start.
- Multiple options | fluent packaging
https://pub.dev/packages/multi_select_item
Multiple items:
Multiple options this is a fluent library that handles multiple options. Using this library, we create a list. When we can delete items in the list, we use this widget. We wrap it in the list view builder project, so that we can easily create a multiple option list.
Implementation plan:
You need to implement it in your code:
Step 1: add dependencies.
Add dependencies to the pubspec(yaml file.
First, add the fluent localization and intl libraries in pubspec. yaml.
dependencies: multi_select_item: ^1.0.3
Step 2: import package:
import 'package:multi_select_item/multi_select_item.dart';
Step 3: enable AndriodX
org.gradle.jvmargs=-Xmx1536M android.enableR8=true android.useAndroidX=true android.enableJetifier=true
Code steps:
To do this, you need to write define controller first.
MultiSelectController controller = new MultiSelectController();
After that, we create a list, which defines its value in initState(), and then determines the set length of the controller according to the length of the list. Refer to the following code included.
@override void initState() { super.initState(); multiSelectList.add({"images": 'assets/images/resort_1.jpg', "desc":"Welcome to New York City!"}); multiSelectList.add({"images":'assets/images/resort_2.jpg' ,"desc":"Welcome to Los Angeles!"}); multiSelectList.add({"images":'assets/images/resort_3.jpg' ,"desc":"Welcome to Chicago!"}); multiSelectList.add({"images":'assets/images/resort_4.jpg', "desc":"Welcome to Houston!"}); controller.disableEditingWhenNoneSelected = true; controller.set(multiSelectList.length); }
After that, we use a ListViewBuilder widget, in which we use the MultiSelectItem() widget, in which we use the card and its sub attributes, and in which we use the row widget, in which we initialize the list value defined above, the list value has image and text, and list it on its onSelected(). The controller is defined inside setState, Used to select values.
ListView.builder( itemCount: multiSelectList.length, itemBuilder: (context, index) { return MultiSelectItem( isSelecting: controller.isSelecting, onSelected: () { setState(() { controller.toggle(index); }); }, child:Container( height:75, margin: EdgeInsets.only(left:15,right:15,top:15), decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), color: Colors._transparent_, ), child:Card( color:controller.isSelected(index) ? Colors._grey_.shade200:Colors._white_, shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(8.0)), ), child:Padding( padding:EdgeInsets.symmetric(vertical:10, horizontal: 12), child: Row( children: [ _//contentPadding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),_ ClipRRect( borderRadius: BorderRadius.circular(12), child:Image.asset(multiSelectList[index]['images'],fit:BoxFit.cover,width:60,height:60,), ), SizedBox(width:20,), Text(multiSelectList[index]['desc'], style: TextStyle(fontSize:14)), ], ), ), ), ), ); }, ),
After that, we will delete the selected item to delete the value we take forEach and sort, which will sort our selected item first from the largest id to the smallest id, and then it will delete it one by one.
void delete() { var list = controller.selectedIndexes; list.sort((b, a) => a.compareTo(b)); list.forEach((element) { multiSelectList.removeAt(element); }); setState(() { controller.set(multiSelectList.length); }); }
All codes:
import 'package:multi_select_item/multi_select_item.dart'; import 'package:flutter/material.dart'; class MultiSelectListDemo extends StatefulWidget { @override _MultiSelectListDemoState createState() => new _MultiSelectListDemoState(); } class _MultiSelectListDemoState extends State<MultiSelectListDemo> { List multiSelectList = []; MultiSelectController controller = new MultiSelectController(); @override void initState() { super.initState(); multiSelectList.add({"images": 'assets/images/resort_1.jpg', "desc":"Welcome to New York City!"}); multiSelectList.add({"images":'assets/images/resort_2.jpg' ,"desc":"Welcome to Los Angeles!"}); multiSelectList.add({"images":'assets/images/resort_3.jpg' ,"desc":"Welcome to Chicago!"}); multiSelectList.add({"images":'assets/images/resort_4.jpg', "desc":"Welcome to Houston!"}); multiSelectList.add({"images":'assets/images/sanfrancisco.jpg', "desc":"Welcome to San francisco!"}); controller.disableEditingWhenNoneSelected = true; controller.set(multiSelectList.length); } void add() { multiSelectList.add({"images": multiSelectList.length}); multiSelectList.add({"desc": multiSelectList.length}); setState(() { controller.set(multiSelectList.length); }); } void delete() { var list = controller.selectedIndexes; list.sort((b, a) => a.compareTo(b)); list.forEach((element) { multiSelectList.removeAt(element); }); setState(() { controller.set(multiSelectList.length); }); } void selectAll() { setState(() { controller.toggleAll(); }); } @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { var before = !controller.isSelecting; setState(() { controller.deselectAll(); }); return before; }, child: new Scaffold( appBar: new AppBar( title: new Text('Selected ${controller.selectedIndexes.length}' ), actions: (controller.isSelecting) ? <Widget>[ IconButton( icon: Icon(Icons._select_all_), onPressed: selectAll, ), IconButton( icon: Icon(Icons._delete_), onPressed: delete, ) ] : <Widget>[], ), body:Container( child: ListView.builder( itemCount: multiSelectList.length, itemBuilder: (context, index) { return InkWell( onTap: () {}, child: MultiSelectItem( isSelecting: controller.isSelecting, onSelected: () { setState(() { controller.toggle(index); }); }, child:Container( height:75, margin: EdgeInsets.only(left:15,right:15,top:15), decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), color: Colors._transparent_, ), child:Card( color:controller.isSelected(index) ? Colors._grey_.shade200:Colors._white_, shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(8.0)), ), child:Padding( padding:EdgeInsets.symmetric(vertical:10, horizontal: 12), child: Row( children: [ _//contentPadding: EdgeInsets.symmetric(vertical: 12, horizontal: 16),_ ClipRRect( borderRadius: BorderRadius.circular(12), child:Image.asset(multiSelectList[index]['images'],fit:BoxFit.cover,width:60,height:60,), ), SizedBox(width:20,), Text(multiSelectList[index]['desc'], style: TextStyle(fontSize:14)), ], ), ), ), ), ), ); }, ), ), ), ); } }
Conclusion:
In this article, I explained explore getit in fluent. You can modify and experiment according to yourself. This little introduction comes from the demonstration of explore getit in fluent from our side.
I hope this blog will provide you with enough information to try to explore GetIt in your Flutter project. We showed you what exploration is and what Flutter is working in your Flutter application, so please try it.
If I do something wrong, please tell me in the comments. I'm happy to improve.
© Cat brother
-
https://ducafecat.tech/
-
https://github.com/ducafecat
-
Wechat group ducafecat
-
Station b https://space.bilibili.com/404904528
Previous period
Open Source
GetX Quick Start
https://github.com/ducafecat/getx_quick_start
News client
https://github.com/ducafecat/flutter_learn_news
Translation of strapi manual
https://getstrapi.cn
Wechat discussion group ducafecat
Series collection
translation
https://ducafecat.tech/categories/%E8%AF%91%E6%96%87/
Open source project
https://ducafecat.tech/categories/%E5%BC%80%E6%BA%90/
Basics of Dart programming language
https://space.bilibili.com/404904528/channel/detail?cid=111585
Introduction to Flutter zero Foundation
https://space.bilibili.com/404904528/channel/detail?cid=123470
Flutter actual combat news client from scratch
https://space.bilibili.com/404904528/channel/detail?cid=106755
Fluent component development
https://space.bilibili.com/404904528/channel/detail?cid=144262
Flutter Bloc
https://space.bilibili.com/404904528/channel/detail?cid=177519
Flutter Getx4
https://space.bilibili.com/404904528/channel/detail?cid=177514
Docker Yapi
https://space.bilibili.com/404904528/channel/detail?cid=130578