Convert string to list Dart

In flutter there is a String Array List function named as StringList.join[] which is used to Convert Complete String Array List Object to Single String Variable in both flutter Android iOS application. Using the join[] method we can put specific alphabets or any other special character between each item of Array String List. The join[] method returns us the complete converted array object into single string.

Contents in this project Flutter Convert Complete String Array List Object to Single String Variable:

1. Open your projects main.dart file and import material.dart package.

1
import 'package:flutter/material.dart';

2. Creating the void main runApp[] method and here we would call our main MyApp class.

1
void main[] => runApp[MyApp[]];

3. Creating the main class named as MyApp extends StatelessWidget. This is our root parent class.

1
2
3
4
5
class MyApp extends StatelessWidget {
}

4. Creating a final type List String Array named as alphabets. In this array we would store some random alphabets.

1
2
3
4
5
6
7
8
9
10
11
12
final List alphabets = [
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J'
];

5. Creating the Widget Build method and here we would first create the Material App widget -> Scaffold widget -> Safe Area Widget -> Center Widget -> Padding widget -> Text Widget.

Note:- In the Text widget we would use the ${alphabets.join["," + " "]}method to convert the List String into single string variable and then print on mobile screen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Widget build[BuildContext context] {
return MaterialApp[
home: Scaffold[
body: SafeArea[
child: Center[
child: Padding[
padding: EdgeInsets.fromLTRB[20, 20, 20, 20],
child: Text[
'${alphabets.join["," + " "]}',
style: TextStyle[fontSize: 20, color: Colors.black],
textAlign: TextAlign.center,
]],
]]]];
}

6. Complete source code for main.dart file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import 'package:flutter/material.dart';
void main[] => runApp[MyApp[]];
class MyApp extends StatelessWidget {
final List alphabets = [
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J'
];
@override
Widget build[BuildContext context] {
return MaterialApp[
home: Scaffold[
body: SafeArea[
child: Center[
child: Padding[
padding: EdgeInsets.fromLTRB[20, 20, 20, 20],
child: Text[
'${alphabets.join["," + " "]}',
style: TextStyle[fontSize: 20, color: Colors.black],
textAlign: TextAlign.center,
]],
]]]];
}
}

Screenshot:

Also Read:

Clear Build Cache in Flutter Android iOS App and Rebuild Project
Setup Install Flutter and Dart Plugin in Android Studio
Flutter Add Assets Images Folder Path in Pubspec.yaml File iOS Android
Find and Remove Special Characters From String in Flutter Dart
List of All Keywords in DART | Reserved Programming Words

Video liên quan

Chủ Đề