Reputation: 53
I want to map each character of words of english_words library. For that I used charaters.map and that works but I want to make container for the each character. this is my code:
// ignore_for_file: prefer_const_literals_to_create_immutables
import 'package:english_words/english_words.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({ Key? key }) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final WordPair words = WordPair.random();
@override
Widget build(BuildContext context) {
return MaterialApp(
// ignore: avoid_print
home: Scaffold(body: Text('${words.first.characters.map((a) => )}''. ',)
),
);
}
}
Upvotes: 1
Views: 367
Reputation: 723
Sample using; (Also you can use list view)
return Column(children: words.first.characters.map((a) => Container(child:Text("$a"))).toList());
Upvotes: 0
Reputation: 63749
WordPair.random().first
returns a String
, that can be represented using ListView
, Column
...
class _MyAppState extends State<MyApp> {
final String fWords = WordPair.random().first;
@override
Widget build(BuildContext context) {
return MaterialApp(
// ignore: avoid_print
home: Scaffold(
body: ListView.builder(
itemCount: fWords.length,
itemBuilder: (context, index) {
return Container(
height: 50,
alignment: Alignment.center,
child: Text(fWords[index]),
);
},
)),
);
}
}
Upvotes: 0
Reputation: 1067
You can wrap the text in a Column
Column(
children: words.first.characters.map((a) =>
Text(a),
).toList(),
)
Upvotes: 2