How Make Copy List Into Another List In Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 10-10-2020

In Flutter copying list into another list is used in many dynamic applications where app developer dose not wants to change the original List. The List library gives us a method named as List.from(old_List). Using this method we can easily make clone of Old List. This method is works on all type of List whether it is String or Integer.

How Make Copy List Into Another List In Flutter Android App

Copy List Into Another List

Complete Code For Copy List Into Another List In Flutter 
main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  List<int> intList = [1, 2, 3, 4,];
  var stringList = ['Apple', 'Bananaa', 'Orange','Mango',];
  void copyList() {
    List<int> newList_1 = List.from(intList);
    var newList_2 = List.from(stringList);
    print(newList_1);
    print(newList_2);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
        home: Scaffold(
            body: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                          margin: const EdgeInsets.fromLTRB(20, 10, 20, 10),
                          child:
                          RaisedButton(
                            onPressed: () => copyList(),
                            child: Text('Copy List Into Another List'),
                            textColor: Colors.white,
                            color: Colors.pink,
                            padding: EdgeInsets.fromLTRB(12, 12, 12, 12),
                          )
                      ),
                    ])
            )
        )
    );
  }
}

Related Post