flutter评论界面
时间: 2023-09-12 14:03:47 浏览: 78
Flutter 提供了许多组件,可以用来构建漂亮的评论界面。以下是一个简单的评论界面的示例:
```dart
import 'package:flutter/material.dart';
class CommentScreen extends StatefulWidget {
@override
_CommentScreenState createState() => _CommentScreenState();
}
class _CommentScreenState extends State<CommentScreen> {
TextEditingController _textEditingController = TextEditingController();
List<String> _commentList = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Comments'),
),
body: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: _commentList.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(_commentList[index]),
);
},
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
controller: _textEditingController,
decoration: InputDecoration(
hintText: 'Add a comment...',
),
),
),
IconButton(
icon: Icon(Icons.send),
onPressed: () {
setState(() {
_commentList.add(_textEditingController.text);
_textEditingController.clear();
});
},
),
],
),
),
],
),
);
}
}
```
这个示例使用了 `Scaffold`、`AppBar`、`Column`、`ListView.builder`、`Container`、`Row`、`TextField` 和 `IconButton` 等 Flutter 组件,以实现一个简单的评论界面。你可以根据自己的需求进行定制和修改。
阅读全文