125 lines
3.1 KiB
Dart
125 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:chatting/chatting_data_page.dart';
|
|
import 'package:chatting/chatting_message_page.dart';
|
|
|
|
/**
|
|
* 聊天主界面
|
|
*/
|
|
|
|
class ChattingDetails extends StatefulWidget {
|
|
|
|
final MessageData messageData;
|
|
|
|
const ChattingDetails({Key key, @required this.messageData}) : super(key: key);
|
|
|
|
@override
|
|
_ChattingDetailsState createState() => _ChattingDetailsState();
|
|
|
|
}
|
|
|
|
class _ChattingDetailsState extends State<ChattingDetails> with TickerProviderStateMixin {
|
|
|
|
final List<ChatMessagePage> _messages = <ChatMessagePage>[];
|
|
|
|
TextEditingController _textEditingController =new TextEditingController();
|
|
|
|
bool _isComposing = false;
|
|
|
|
void _handleSubmitted(String text) {
|
|
_textEditingController.clear();
|
|
|
|
setState((){
|
|
_isComposing = false;
|
|
});
|
|
|
|
ChatMessagePage message = new ChatMessagePage(
|
|
text: text,
|
|
animationController: new AnimationController(
|
|
duration: new Duration(milliseconds: 700),
|
|
vsync: this
|
|
),
|
|
messageData: widget.messageData,
|
|
);
|
|
setState((){
|
|
_messages.insert(0, message);
|
|
});
|
|
message.animationController.forward();
|
|
}
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(widget.messageData.title),
|
|
centerTitle: true,
|
|
),
|
|
body: Column(
|
|
children: <Widget>[
|
|
Flexible(
|
|
child: ListView.builder(
|
|
padding: const EdgeInsets.all(8.0),
|
|
reverse: true,
|
|
itemCount: _messages.length,
|
|
itemBuilder: (_,int index){
|
|
|
|
return _messages[index];
|
|
},
|
|
),
|
|
),
|
|
Divider(height: 1.0,),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).cardColor,
|
|
),
|
|
child: row()
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget row (){
|
|
return IconTheme(
|
|
//data: IconThemeData(color: Theme.of(context).accentColor),
|
|
data: IconThemeData(color: Colors.pink),
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Flexible(
|
|
child: TextField(
|
|
controller: _textEditingController,
|
|
onChanged: (String text) {
|
|
setState((){
|
|
_isComposing = text.length > 0;
|
|
});
|
|
},
|
|
onSubmitted: _handleSubmitted,
|
|
decoration: new InputDecoration.collapsed(hintText: '发送消息'),
|
|
),
|
|
),
|
|
Container(
|
|
margin: new EdgeInsets.symmetric(horizontal: 4.0),
|
|
child: new IconButton(
|
|
icon: new Icon(Icons.send),
|
|
onPressed: _isComposing ? () => _handleSubmitted(_textEditingController.text) : null
|
|
),
|
|
)
|
|
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
@override
|
|
void dispose() {
|
|
for(ChatMessagePage message in _messages)
|
|
message.animationController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
}
|