Flutter - Using Tuples Last Updated : 08 Feb, 2022 Comments Improve Suggest changes Like Article Like Report A tuple is a collection of items that could be dissimilar. It is the list-like data type. Since it is not a built-in data type in Flutter we need a tuple package to include it in the project. Let's discuss tuple in the Flutter in this article. Add in the Dependency: In Flutter, a tuple needs to be added as a dependency in pubspec.yaml. Then run pub get to install it. Import in main.dart: To add tuple functionality, add it in main.dart. Dart import 'package:tuple/tuple.dart'; Example 1: The tuple can be created of different sizes up to length 7 in Flutter. Let us see an example where we create a tuple of size 2. The items in the tuple are dynamic, independent of data type. We declared a const variable t and initialized it as a tuple. Then we print the values stored in t by accessing them through item1, and item2. Dart const t = Tuple2<String, int>('geeksforgeeks', 10); print(t.item1); print(t.item2); Output: Example 2: We created a tuple t2 of length 2 and accessed the item1 which is "geeksforgeeks". Then, we replaced the value of the third item of the tuple using the withItem3() function. The third item value which is 10 will be replaced as 20. Dart const t2 = Tuple3('geeksforgeeks', 'tutorial', 10); print(t2.item1); print(t2.withItem3(20)); Output: Example 3: Let's declare a tuple of length 7 and then convert it into the list using the toList() method. Dart const t3 = Tuple7(1, 2, 3, 4, 5, 6, 7); print(t3.toList()); Output: Example 4: We can also create a tuple from a list. For example, declare a list of integers items and then use the tuple of size items length and use the fromList() method to convert that list into a Tuple. Dart List items = [1, 2, 3, 4, 5, 6]; var t4 = Tuple6.fromList(items); print(t4); Output: Comment More infoAdvertise with us Next Article Flutter - Using Tuples R rn540 Follow Improve Article Tags : Flutter Android Flutter Similar Reads Flutter - Stepper Widget In this article, we will learn about the Stepper widget in Flutter. A stepper widget displays progress through a sequence of steps. A stepper is generally used in filling out forms online.For example, remember filling out an online form for applying to any university or passport, or driving license. 6 min read Flutter - ListTile Widget The ListTile widget is used to populate a ListView in Flutter. It contains a title as well as leading or trailing icons. Let's understand this with the help of an example.Constructor of the ListTile classListTile ListTile({ Key? key, Widget? leading, Widget? title, Widget? subtitle, Widget? trailing 5 min read Flutter - Grouped List The grouped_list package in Flutter as the name suggests is used to create list items in different groups. This package also provides 3 specific functions that are listed below:List Items can be separated into groups.An individual header can be given to each group.Most fields from the ListView.build 5 min read Table Widget in Flutter Table widget is used to display items in a table layout. There is no need to use Rows and Columns to create a table. If we have multiple rows with the same width of columns then Table widget is the right approach. SliverList or Column will be most suitable if we only want to have a single column. Th 3 min read Flutter - Stateful Widget A Stateful Widget has states in it. To understand a Stateful Widget, you need to have a clear understanding of widgets and state management. A state can be defined as "an imperative changing of the user interface," and a widget is "an immutable description of the part of the user interface". To lear 4 min read Like