<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Esmaeil Ahmadipour</title>
    <description>The latest articles on DEV Community by Esmaeil Ahmadipour (@esmaeilahmadipour).</description>
    <link>https://dev.to/esmaeilahmadipour</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F891025%2Fdb343a77-a7dc-48c6-901a-b1577dd2729d.png</url>
      <title>DEV Community: Esmaeil Ahmadipour</title>
      <link>https://dev.to/esmaeilahmadipour</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/esmaeilahmadipour"/>
    <language>en</language>
    <item>
      <title>Unlocking the Power of Generics in Dart: Using List, Set, Map, and Queue Collections</title>
      <dc:creator>Esmaeil Ahmadipour</dc:creator>
      <pubDate>Fri, 10 Mar 2023 00:07:33 +0000</pubDate>
      <link>https://dev.to/esmaeilahmadipour/unlocking-the-power-of-generics-in-dart-using-list-set-map-and-queue-collections-3g4l</link>
      <guid>https://dev.to/esmaeilahmadipour/unlocking-the-power-of-generics-in-dart-using-list-set-map-and-queue-collections-3g4l</guid>
      <description>&lt;p&gt;Generics are a powerful feature of the Dart language that allow us to create collections that can only hold a single type of data. This ensures type safety and prevents us from accidentally adding the wrong type of data to a collection. Generics can be used with List, Set, Map, and Queue collections.&lt;/p&gt;

&lt;p&gt;For example, a List can only hold strings, a Set can only hold integers, a Map can only hold key-value pairs where the key is a string and the value is an integer, and a Queue can only hold strings.&lt;/p&gt;

&lt;p&gt;Using generics also allows us to easily access the data stored in a collection. For example, if we have a List we know that all of the elements in the list will be strings and we can easily access them without having to worry about type errors. Similarly, if we have a Map we know that all of the keys will be strings and all of the values will be integers and we can easily access them without having to worry about type errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 𝗟𝗶𝘀𝘁
&lt;/h2&gt;

&lt;p&gt;In Dart, a List is simply an ordered group of objects. A list is simple an implementation of an array.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;T&amp;gt; list = new List&amp;lt;String&amp;gt;();
list.add("John");
list.add("Mary");
list.add("Bob");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Set
&lt;/h2&gt;

&lt;p&gt;In Dart, a Set represents a collection of objects in which each object can exist only once.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set&amp;lt;T&amp;gt; set = new Set&amp;lt;Product&amp;gt;();
set.add(new Product("Shirt"));
set.add(new Product("Pants"));
set.add(new Product("Hat"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Map
&lt;/h2&gt;

&lt;p&gt;In Dart, Map is a dynamic collection of the key, value pairs.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Map&amp;lt;K, V&amp;gt; map = new Map&amp;lt;String, Customer&amp;gt;();
map["John"] = new Customer("John", 25);
map["Mary"] = new Customer("Mary", 30);
map["Bob"] = new Customer("Bob", 28);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 𝗤𝘂𝗲𝘂𝗲
&lt;/h2&gt;

&lt;p&gt;A queue is a collection that is used when the data is to be inserted in a FIFO (First in first out) manner. In Dat, a queue can be manipulated at both ends, i.e. at the start as well as the end of the queue.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Queue&amp;lt;T&amp;gt; queue = new Queue&amp;lt;Order&amp;gt;();
queue.add(new Order("Red Shirt"));
queue.add(new Order("Green Pants"));
queue.add(new Order("Blue Hat"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Class &amp;amp; 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Functions
&lt;/h2&gt;

&lt;p&gt;Generics can also be used to create custom classes and functions. This allows us to create classes and functions that can be used with any type of data.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Class
class MyClass&amp;lt;T&amp;gt; { 
T data;
 MyClass(this.data);
   void printData() {
     print(data); } 
} 

// 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Functions
void myFunction&amp;lt;T&amp;gt;(T data) {
   print(data); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Example In Flutter
&lt;/h2&gt;

&lt;p&gt;In below example, we have created a generic class called MyClass that can be used to store any type of data.&lt;br&gt;
We have also created a object called WidgetListItem that takes a MyClass object and displays the data stored in it.&lt;br&gt;
And we have used generics to ensure that the data stored in the MyClass object is of the correct type and that the WidgetListItem object can be used with any type of data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

class MyClass&amp;lt;T,K&amp;gt; {
  Map&amp;lt;T,K&amp;gt;  data;
  Map&amp;lt;String,String&amp;gt;? type;

  MyClass(this.data, [this.type]) {
//The "type" variable is used to show "runtimeType" of the "MyClass" variables.
    type = {"${data.entries.first.key.runtimeType}":"${data.entries.first.value.runtimeType}"};
  }
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // We defines 3 object from generic classes
    MyClass universityName_term = MyClass&amp;lt;String,int&amp;gt;({"CentralUniversity":3});
    MyClass salary_tax = MyClass&amp;lt;int,double&amp;gt;({1000:0.09});
    MyClass firstName_lastName = MyClass&amp;lt;String,String&amp;gt;({"Esmaeil":"Ahmadipour"});

    return MaterialApp(
      title: 'Generics Demo',
      home: Scaffold(
        appBar: AppBar(title: const Text('Using Generics')),
        body: Center(
          child: Padding(
              padding: const EdgeInsets.all(48.0),
              child:Column(
                children: [
                  const WidgetListTitle(),
                  WidgetListItem(myClass: universityName_term,color: Colors.red.shade300),
                  WidgetListItem(myClass: salary_tax,color: Colors.green.shade300),
                  WidgetListItem(myClass: firstName_lastName,color: Colors.blue.shade300),
                ],
              )
          ),
        ),
      ),
    );
  }
}

class WidgetListTitle extends StatelessWidget {
  const WidgetListTitle({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: const [
        Text('Map Side'),
        Text('Side Value'),
        Text('ValueType'),
      ],
    );
  }
}

class WidgetListItem extends StatelessWidget {
  const WidgetListItem({
    Key? key,
    required this.myClass, required this.color,
  }) : super(key: key);

  final MyClass myClass;
  final Color color;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(8.0),
      color: color,
      child: Column(
        children: &amp;lt;Widget&amp;gt;[

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const Text('Kay:'),
              Text('${myClass.data.entries.first.key}'),
              Text(myClass.type!.entries.first.key),
            ],
          ),
          const Divider(),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const Text('Value:'),
              Text('${myClass.data.entries.first.value}'),
              Text(myClass.type!.entries.first.value),
            ],
          ),
        ],
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>flutter</category>
      <category>flutterdev</category>
      <category>dart</category>
    </item>
    <item>
      <title>Understanding the Basics of Mockito in Flutter(Part1)</title>
      <dc:creator>Esmaeil Ahmadipour</dc:creator>
      <pubDate>Wed, 08 Mar 2023 20:24:40 +0000</pubDate>
      <link>https://dev.to/esmaeilahmadipour/understanding-the-basics-of-mockito-in-flutterpart1-2g60</link>
      <guid>https://dev.to/esmaeilahmadipour/understanding-the-basics-of-mockito-in-flutterpart1-2g60</guid>
      <description>&lt;p&gt;&lt;strong&gt;#Introduction to Mockito in Flutter&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;M&lt;/strong&gt;ockito is a powerful mocking framework for unit testing in Flutter, allowing developers to create mock objects that simulate the behavior of real objects in controlled ways.&lt;br&gt;
This helps developers to test the functionality of their code without having to rely on external dependencies. It also helps to identify bugs and errors in the code, as it isolates the code under test and verifies its behavior.&lt;br&gt;
With Mockito, developers can create mocks of classes, interfaces, and even functions, allowing them to test their code in isolation and ensure that their code is working as expected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#Setting up Mockito in flutter&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;M&lt;/strong&gt;ockito is a popular mocking framework for unit testing in Java. It is now available for Flutter developers as well, thanks to the mocktail package. Setting up Mockito in Flutter and using the mocktail package is easy and straightforward.&lt;br&gt;
The mocktail package provides a Mock class that can be used to create a mock object of any class. The mock object can then be used to define the behavior of the class and write tests.&lt;br&gt;
In the example above, we have created a Calculator class with an add() method that takes two numbers as parameters and returns their sum. To test this method, we have created a mock object of the Calculator class using the Mock class provided by the mocktail package. We have then defined the behavior of the mock object using the when() method. Finally, we have written a test to verify that the mock object returns the expected result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// Full Code ;)

import 'package:test/test.dart';
import 'package:mocktail/mocktail.dart';

class MockCalculator extends Mock implements Calculator {}

void main() {

  test('add() should return the sum of two numbers', () {
// This is a test to verify the behavior of the add() method of the Calculator class.
// First, a mock object of the Calculator class is created.
    var  calculator = MockCalculator();

// The behavior of the mock object is then defined.
// When the add() method is called with 1 and 2 as parameters, it should return 3.
    when(() =&amp;gt;calculator.add(1, 2)).thenReturn(3);

// The test is written to call the add() method with 1 and 2 as parameters.
    int result = calculator.add(1, 2);

// Finally, the result is verified to be 3, which is the expected result.
    expect(result, 3);
  });
}

class Calculator {
  int add(int a, int b) {
    return a + b;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;#Writing Unit Tests with Mockito in flutter&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;W&lt;/strong&gt;riting unit tests with Mockito in Flutter is a great way to ensure that your code is working as expected. Mockito is a mocking framework that allows you to create mock objects and stub methods for testing. With Mockito, you can easily create mocks of classes and methods, and then use them to test your code.&lt;/p&gt;

&lt;p&gt;In this section , we’ll be looking at how to write unit tests with Mockito in Flutter. We’ll be using the MyClass class from the example above as our example class. We’ll be writing tests for the setData() and getData() methods of MyClass.&lt;/p&gt;

&lt;p&gt;First, we’ll need to import the Mocktail library and the test package. Then, we’ll create a MyClassMock class that extends the Mock class. This will allow us to create mock objects of our MyClass class.&lt;/p&gt;

&lt;p&gt;Next, we’ll create a setUp() method that will create an instance of MyClassMock and MyClass. This will allow us to use these instances in our tests.&lt;/p&gt;

&lt;p&gt;Then, we’ll create a group() method that will group our tests together. This will make it easier to read our tests and understand what they are testing.&lt;/p&gt;

&lt;p&gt;Finally, we’ll write three test() methods that will test the setData() and getData() methods of MyClass, as well as the getData() method of MyClassMock with a default value.&lt;/p&gt;

&lt;p&gt;Once we have written our tests, we can run them to make sure that our code is working as expected. If any of the tests fail, we can go back and debug our code until all of the tests pass.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/// Full Code ;)
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class MyClassMock extends Mock implements MyClass {}

// This test suite is used to test the functionality of the MyClass class.
void main() {
  late MyClassMock myClassMock;
  late MyClass myClass;
// The setUp() method is used to create an instance of MyClassMock and MyClass.
  setUp(() {
    myClassMock = MyClassMock();
    myClass = MyClass();
  });
// The group() method is used to group the tests together.
  group('do setData and getData succeed', () {
// The first test() method is used to test the setData() and getData() methods of MyClass.
    test('setData', () {
      myClass.setData("test");
      expect(myClass.getData(), equals("test"));
    });
// The second test() method is used to test the getData() method of MyClassMock.
    test('getData', () {
      when(() =&amp;gt; myClassMock.getData()).thenReturn("TEST");
      expect(myClassMock.getData(), equals("TEST"));
    });
// The third test() method is used to test the getData() method of MyClassMock with a default value.
    test('getData with default value', () {
      expect(myClassMock.getData(), equals(null));
    });
  });
}

class MyClass {
  String? _data;

  String? getData() {
    return _data;
  }

  void setData(String data) {
    _data = data;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>flutter</category>
      <category>flutterdev</category>
      <category>fluttertest</category>
    </item>
    <item>
      <title>The Challenge of Using the Same Code Base for Android and Web: A Conceptual Overview</title>
      <dc:creator>Esmaeil Ahmadipour</dc:creator>
      <pubDate>Wed, 08 Mar 2023 20:18:29 +0000</pubDate>
      <link>https://dev.to/esmaeilahmadipour/the-challenge-of-using-the-same-code-base-for-android-and-web-a-conceptual-overview-36fl</link>
      <guid>https://dev.to/esmaeilahmadipour/the-challenge-of-using-the-same-code-base-for-android-and-web-a-conceptual-overview-36fl</guid>
      <description>&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;re you a programmer looking for a way to write code that works on both Android and web platforms? If so, you’ve come to the right place!&lt;br&gt;
In this article, we’ll explore the concept of using the same code base for both Android and web platforms. We’ll look at how to write code that works on both platforms, as well as some of the challenges you may face when doing so.&lt;br&gt;
The first step in writing code that works on both Android and web platforms is to import the appropriate libraries.&lt;/p&gt;

&lt;p&gt;For web browsers, you’ll need to import 'dart:html'.&lt;br&gt;
For Android devices, you’ll need to import 'dart:ui'.&lt;/p&gt;

&lt;p&gt;Here’s an example of how to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';
import 'dart:html' as html; // For web browser.
import 'dart:ui' as ui; // For Android device.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you’ll need to create a StatelessWidget class that contains the code that will be used for both Android and web platforms. Here’s an example of how to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyApp extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
 // Check the platform and use the appropriate library.

 if (html.window != null) { 
// Running on web browser.

// Create a new file.
 File('my_file.txt').create();

// Write to a file.
 File('my_file.txt').writeAsStringSync('Hello World!');

// Read the content of a file.
 String content = File('my_file.txt').readAsStringSync();
return Text(content);
 } else if (ui.window != null) {
// Running on Android device.

// Create a new file.
 File('my_file.txt').create();

// Write to a file.
 File('my_file.txt').writeAsStringSync('Hello World!');

// Read the content of a file.
 String content = File('my_file.txt').readAsStringSync();
return Text(content);
 } else {

// Unknown platform.
 return Text('Unknown platform!');
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you’ll need to call the runApp() method with your StatelessWidget class as an argument. This will ensure that your code runs on both Android and web platforms. Here’s an example of how to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main(){ 
runApp(MaterialApp( 
  home: Scaffold(body:Center(child:MyApp())),
  )); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, can we do it another way?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Y&lt;/strong&gt;ou can create three files that will allow you to switch between native and web code.&lt;/p&gt;

&lt;p&gt;The first file, web.dart, will contain code specific to web applications. This file should import the dart:html library and contain any functions or variables that are specific to web applications. For example, the following code contains a reload() function that reloads the current page and a cookie variable that stores a cookie value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'dart:html' as html;

void reload() {
  html.window.location.reload();
}

String cookie = "";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second file, native.dart, will contain code specific to native applications. This file should not import the dart:html library and should contain any functions or variables that are specific to native applications. For example, the following code contains an empty reload() function and a cookie variable that stores a cookie value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void reload() {}

String cookie = "";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The third file, switch_native_web.dart, will contain code that allows you to switch between native and web code. This file should import both the native.dart and web.dart files and contain a class that allows you to access functions and variables from either file depending on whether the application is running on a web or native platform. For example, the following code contains a SwitchNativeWeb class that allows you to access either the reload() function from web.dart or the empty reload() function from native.dart depending on which platform the application is running on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'native.dart' if (dart.library.html) 'web.dart' as switch_value;

class SwitchNativeWeb {

  static String cookie = switch_value.cookie;

  static void reloadWeb() {
    switch_value.reload();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By creating these three files, you can easily switch between native and web code depending on which platform your application is running on. This will allow you to write code that is optimized for both platforms without having to duplicate code or maintain two separate versions of your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// You can use like below code.

String cookie = SwitchNativeWeb.cookie; 
.
.
onTap:(){
   SwitchNativeWeb.reloadWeb();
}
.
.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DyWCT6aE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dthtm1o68uc3b0jmfnby.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DyWCT6aE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dthtm1o68uc3b0jmfnby.gif" alt="Secend method of Same Code Base" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>flutterweb</category>
      <category>flutterandroid</category>
      <category>flutterdev</category>
    </item>
    <item>
      <title>Unlocking the Power of Generics in Dart: Using List, Set, Map, and Queue Collections</title>
      <dc:creator>Esmaeil Ahmadipour</dc:creator>
      <pubDate>Wed, 08 Mar 2023 19:47:58 +0000</pubDate>
      <link>https://dev.to/esmaeilahmadipour/unlocking-the-power-of-generics-in-dart-using-list-set-map-and-queue-collections-3o85</link>
      <guid>https://dev.to/esmaeilahmadipour/unlocking-the-power-of-generics-in-dart-using-list-set-map-and-queue-collections-3o85</guid>
      <description>&lt;p&gt;Generics are a powerful feature of the Dart language that allow us to create collections that can only hold a single type of data. This ensures type safety and prevents us from accidentally adding the wrong type of data to a collection. Generics can be used with List, Set, Map, and Queue collections.&lt;/p&gt;

&lt;p&gt;For example, a List can only hold strings, a Set can only hold integers, a Map can only hold key-value pairs where the key is a string and the value is an integer, and a Queue can only hold strings.&lt;/p&gt;

&lt;p&gt;Using generics also allows us to easily access the data stored in a collection. For example, if we have a List we know that all of the elements in the list will be strings and we can easily access them without having to worry about type errors. Similarly, if we have a Map we know that all of the keys will be strings and all of the values will be integers and we can easily access them without having to worry about type errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt;𝗚𝗲𝗻𝗲𝗿𝗶𝗰 𝗟𝗶𝘀𝘁&lt;/p&gt;

&lt;p&gt;In Dart, a List is simply an ordered group of objects. A list is simple an implementation of an array.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;T&amp;gt; list = new List&amp;lt;String&amp;gt;();

list.add("John");

list.add("Mary");

list.add("Bob");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt;𝗚𝗲𝗻𝗲𝗿𝗶𝗰 𝗦𝗲𝘁&lt;/p&gt;

&lt;p&gt;In Dart, a Set represents a collection of objects in which each object can exist only once.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set&amp;lt;T&amp;gt; set = new Set&amp;lt;Product&amp;gt;();

set.add(new Product("Shirt"));

set.add(new Product("Pants"));

set.add(new Product("Hat"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt;𝗚𝗲𝗻𝗲𝗿𝗶𝗰 𝗠𝗮𝗽&lt;/p&gt;

&lt;p&gt;In Dart, Map is a dynamic collection of the key, value pairs.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Map&amp;lt;K, V&amp;gt; map = new Map&amp;lt;String, Customer&amp;gt;();

map["John"] = new Customer("John", 25);

map["Mary"] = new Customer("Mary", 30);

map["Bob"] = new Customer("Bob", 28);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt;𝗚𝗲𝗻𝗲𝗿𝗶𝗰 𝗤𝘂𝗲𝘂𝗲&lt;/p&gt;

&lt;p&gt;A queue is a collection that is used when the data is to be inserted in a FIFO (First in first out) manner. In Dat, a queue can be manipulated at both ends, i.e. at the start as well as the end of the queue.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Queue&amp;lt;T&amp;gt; queue = new Queue&amp;lt;Order&amp;gt;();

queue.add(new Order("Red Shirt"));

queue.add(new Order("Green Pants"));

queue.add(new Order("Blue Hat"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Class &amp;amp; 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Functions&lt;br&gt;
Generics can also be used to create custom classes and functions. This allows us to create classes and functions that can be used with any type of data.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Class
class MyClass&amp;lt;T&amp;gt; { 
T data;
 MyClass(this.data);
   void printData() {
     print(data); } 
} 

// 𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Functions
void myFunction&amp;lt;T&amp;gt;(T data) {
   print(data); 
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;𝗚𝗲𝗻𝗲𝗿𝗶𝗰 Example In Flutter&lt;/strong&gt;&lt;br&gt;
In below example, we have created a generic class called MyClass that can be used to store any type of data.&lt;br&gt;
We have also created a object called WidgetListItem that takes a MyClass object and displays the data stored in it.&lt;br&gt;
And we have used generics to ensure that the data stored in the MyClass object is of the correct type and that the WidgetListItem object can be used with any type of data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

class MyClass&amp;lt;T,K&amp;gt; {
  Map&amp;lt;T,K&amp;gt;  data;
  Map&amp;lt;String,String&amp;gt;? type;

  MyClass(this.data, [this.type]) {
//The "type" variable is used to show "runtimeType" of the "MyClass" variables.
    type = {"${data.entries.first.key.runtimeType}":"${data.entries.first.value.runtimeType}"};
  }
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // We defines 3 object from generic classes
    MyClass universityName_term = MyClass&amp;lt;String,int&amp;gt;({"CentralUniversity":3});
    MyClass salary_tax = MyClass&amp;lt;int,double&amp;gt;({1000:0.09});
    MyClass firstName_lastName = MyClass&amp;lt;String,String&amp;gt;({"Esmaeil":"Ahmadipour"});

    return MaterialApp(
      title: 'Generics Demo',
      home: Scaffold(
        appBar: AppBar(title: const Text('Using Generics')),
        body: Center(
          child: Padding(
              padding: const EdgeInsets.all(48.0),
              child:Column(
                children: [
                  const WidgetListTitle(),
                  WidgetListItem(myClass: universityName_term,color: Colors.red.shade300),
                  WidgetListItem(myClass: salary_tax,color: Colors.green.shade300),
                  WidgetListItem(myClass: firstName_lastName,color: Colors.blue.shade300),
                ],
              )
          ),
        ),
      ),
    );
  }
}

class WidgetListTitle extends StatelessWidget {
  const WidgetListTitle({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: const [
        Text('Map Side'),
        Text('Side Value'),
        Text('ValueType'),
      ],
    );
  }
}

class WidgetListItem extends StatelessWidget {
  const WidgetListItem({
    Key? key,
    required this.myClass, required this.color,
  }) : super(key: key);

  final MyClass myClass;
  final Color color;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(8.0),
      color: color,
      child: Column(
        children: &amp;lt;Widget&amp;gt;[

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const Text('Kay:'),
              Text('${myClass.data.entries.first.key}'),
              Text(myClass.type!.entries.first.key),
            ],
          ),
          const Divider(),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              const Text('Value:'),
              Text('${myClass.data.entries.first.value}'),
              Text(myClass.type!.entries.first.value),
            ],
          ),
        ],
      ),
    );
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>flutter</category>
      <category>dart</category>
      <category>flutterdev</category>
    </item>
    <item>
      <title>How to work javascript file in flutter web ?</title>
      <dc:creator>Esmaeil Ahmadipour</dc:creator>
      <pubDate>Wed, 08 Mar 2023 19:39:27 +0000</pubDate>
      <link>https://dev.to/esmaeilahmadipour/how-to-work-javascript-file-in-flutter-web--1ak5</link>
      <guid>https://dev.to/esmaeilahmadipour/how-to-work-javascript-file-in-flutter-web--1ak5</guid>
      <description>&lt;p&gt;One of the capabilities of using flutter for development is creating pwa output. Can we change the final web output (html file) with the commands we wrote in dart? Can we add a tag (like meta or p, …) to the html file with dart commands? You can see how to do this in the following article.&lt;/p&gt;

&lt;p&gt;To start, use the default project (counter app) in flutter!&lt;/p&gt;

&lt;p&gt;At the top of the main file we add this line:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import 'dart: js' as dartJsFile;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In setState from the _incrementCounter method we add this line:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

dartJsFile.context.callMethod ('insertTag');



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we need to write the JavaScript file. To do this, we need to write the following command in the app terminal:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

flutter create.



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Add your JavaScript file to the project as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5bpr5os6mzmlnwog9qu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5bpr5os6mzmlnwog9qu.png" alt="In the build&amp;gt; web folder .."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my example , I have to write a method called (insertTag) in my js file that adds new tags inside a tag called (seo). In the file (app .js) I created, I write the method (insertTag):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

function insertTag () {
var tag = document.createElement ("meta");
tag.setAttribute ("name", "custom name");
tag.setAttribute ("content", "custom content");
var element = document.getElementById ("seo");
element.appendChild (tag);
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And in the head of the index .html file, I call it.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;head&amp;gt; &amp;lt;script src = "app.js"&amp;gt; &amp;lt;/script&amp;gt; &amp;lt;/head&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And inside the body, I define a tag called seo.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;body&amp;gt; &amp;lt;div id = "seo"&amp;gt; &amp;lt;/div&amp;gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, after performing deploy operations on the server or localhost, you can add a new tag to your file (index.html) each time you press the (+) button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fosmdliwlvbyq04w58igx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fosmdliwlvbyq04w58igx.png" alt="now worked javascript file in flutter web"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>flutterdev</category>
      <category>javascript</category>
      <category>flutterweb</category>
    </item>
  </channel>
</rss>
