我可以在映射資料時顯示(使用顫振)
主要.dart
//Im looping on it using map
List<Quote> quotes = [
Quote(
author: 'Oscar Wilde',
text: 'Be yourself, everyone else is already taken'),
Quote(
author: 'Oscar Wilde',
text: 'I have nothing to declare except my genius'),
Quote(
author: 'Oscar Wilde',
text: 'The truth is rarely pure and never simple'),
];
// Im using map then not display on the screen
body: Column(
children: quotes.map((quote) => Text(quote)).toList(),
),
非常感謝你

uj5u.com熱心網友回復:
要添加卡,請執行以下操作:
@override
Widget build(BuildContext context) {
return Column(
children: List<Widget>.generate(
quotes.length,
(index) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40), // if you need this
side: BorderSide(
color: Colors.grey.withOpacity(0.2),
width: 1,
),
),
child: Container(
color: Colors.white,
width: 200,
height: 200,
child: Text('${quotes[index].author}'),
),
);
},
),
);
}
uj5u.com熱心網友回復:
您可以嘗試使用串列生成器而不是地圖。或者您使用 @Jahn 提到的 Listview 構建器
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
List<Quote> quotes = [
Quote(
author: 'Oscar Wilde',
text: 'Be yourself, everyone else is already taken'),
Quote(
author: 'Oscar Wilde',
text: 'I have nothing to declare except my genius'),
Quote(
author: 'Oscar Wilde',
text: 'The truth is rarely pure and never simple'),
];
@override
Widget build(BuildContext context) {
return Column(
children: List<Widget>.generate(
quotes.length,
(index) {
return Text('${quotes[index].author}');
},
),
);
}
}
class Quote {
String? author;
String? text;
Quote({this.author, this.text});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/411609.html
標籤:
上一篇:使用自定義外部小部件顫動
