|
|
@ -1,14 +1,13 @@
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ThemeData kIOSTheme = ThemeData(
|
|
|
|
final ThemeData kIOSTheme = ThemeData(
|
|
|
|
primarySwatch: Colors.orange,
|
|
|
|
primarySwatch: Colors.orange,
|
|
|
|
primaryColor: Colors.grey[100],
|
|
|
|
primaryColor: Colors.grey[100],
|
|
|
|
primaryColorBrightness: Brightness.light
|
|
|
|
primaryColorBrightness: Brightness.light,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final ThemeData kDefaultTheme = ThemeData(
|
|
|
|
final ThemeData kDefaultTheme = ThemeData(
|
|
|
|
primarySwatch: Colors.purple,
|
|
|
|
primarySwatch: Colors.purple,
|
|
|
|
accentColor: Colors.orangeAccent
|
|
|
|
accentColor: Colors.orangeAccent,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
runApp(FriendlychatApp());
|
|
|
|
runApp(FriendlychatApp());
|
|
|
@ -21,7 +20,9 @@ class FriendlychatApp extends StatelessWidget {
|
|
|
|
Widget build(BuildContext build) {
|
|
|
|
Widget build(BuildContext build) {
|
|
|
|
return MaterialApp(
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Friendlychat',
|
|
|
|
title: 'Friendlychat',
|
|
|
|
theme: Theme.of(build).platform == TargetPlatform.iOS ? kIOSTheme : kDefaultTheme,
|
|
|
|
theme: Theme.of(build).platform == TargetPlatform.iOS
|
|
|
|
|
|
|
|
? kIOSTheme
|
|
|
|
|
|
|
|
: kDefaultTheme,
|
|
|
|
home: ChatAppHomePage(title: 'Friendlychat'),
|
|
|
|
home: ChatAppHomePage(title: 'Friendlychat'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -32,7 +33,6 @@ class ChatAppHomePage extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
_ChatAppHomePageState createState() => _ChatAppHomePageState();
|
|
|
|
_ChatAppHomePageState createState() => _ChatAppHomePageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -80,7 +80,7 @@ class TwoPaneChatLayout extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
return Row(
|
|
|
|
children: <Widget>[
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
Container(
|
|
|
|
child: ChatListScreen(chatEntries: chatEntries),
|
|
|
|
child: ChatListScreen(chatEntries: chatEntries),
|
|
|
|
constraints: BoxConstraints(minWidth: 100, maxWidth: 300),
|
|
|
|
constraints: BoxConstraints(minWidth: 100, maxWidth: 300),
|
|
|
@ -107,21 +107,20 @@ class ChatListScreen extends StatelessWidget {
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return ListTile(
|
|
|
|
return ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
child: Text(chatEntries[index].name[0])
|
|
|
|
child: Text(chatEntries[index].name[0]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
title: Text(chatEntries[index].name),
|
|
|
|
title: Text(chatEntries[index].name),
|
|
|
|
onTap: () {
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
Navigator.push<void>(
|
|
|
|
context,
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
MaterialPageRoute<void>(
|
|
|
|
builder: (context) => ChatScreen(
|
|
|
|
builder: (context) =>
|
|
|
|
contactName: chatEntries[index].name
|
|
|
|
ChatScreen(contactName: chatEntries[index].name),
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -139,7 +138,7 @@ class ChatScreen extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
|
|
class ChatScreenState extends State<ChatScreen> with TickerProviderStateMixin {
|
|
|
|
class ChatScreenState extends State<ChatScreen> with TickerProviderStateMixin {
|
|
|
|
final TextEditingController _textController = TextEditingController();
|
|
|
|
final TextEditingController _textController = TextEditingController();
|
|
|
|
final List<ChatMessage> _messages = <ChatMessage>[];
|
|
|
|
final List<ChatMessage> _messages = [];
|
|
|
|
final String contactName;
|
|
|
|
final String contactName;
|
|
|
|
|
|
|
|
|
|
|
|
ChatScreenState({@required this.contactName}) : super();
|
|
|
|
ChatScreenState({@required this.contactName}) : super();
|
|
|
@ -149,14 +148,14 @@ class ChatScreenState extends State<ChatScreen> with TickerProviderStateMixin {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
return Scaffold(
|
|
|
|
body: Column(
|
|
|
|
body: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
Flexible(
|
|
|
|
child: ListView.builder(
|
|
|
|
child: ListView.builder(
|
|
|
|
padding: EdgeInsets.all(8.0),
|
|
|
|
padding: EdgeInsets.all(8.0),
|
|
|
|
reverse: true,
|
|
|
|
reverse: true,
|
|
|
|
itemBuilder: (_, int index) => _messages[index],
|
|
|
|
itemBuilder: (_, index) => _messages[index],
|
|
|
|
itemCount: _messages.length,
|
|
|
|
itemCount: _messages.length,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Divider(height: 1.0),
|
|
|
|
Divider(height: 1.0),
|
|
|
|
Container(
|
|
|
|
Container(
|
|
|
@ -164,7 +163,7 @@ class ChatScreenState extends State<ChatScreen> with TickerProviderStateMixin {
|
|
|
|
child: _buildTextComposer(),
|
|
|
|
child: _buildTextComposer(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
],
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -182,30 +181,33 @@ class ChatScreenState extends State<ChatScreen> with TickerProviderStateMixin {
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
child: Row(
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
Flexible(
|
|
|
|
child: TextField(
|
|
|
|
child: TextField(
|
|
|
|
controller: _textController,
|
|
|
|
controller: _textController,
|
|
|
|
onSubmitted: _handleSubmitted,
|
|
|
|
onSubmitted: _handleSubmitted,
|
|
|
|
decoration: InputDecoration.collapsed(hintText: "Send a message"),
|
|
|
|
decoration:
|
|
|
|
onChanged: (String text) {
|
|
|
|
InputDecoration.collapsed(hintText: "Send a message"),
|
|
|
|
|
|
|
|
onChanged: (text) {
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
_isComposing = text.length > 0;
|
|
|
|
_isComposing = text.isNotEmpty;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 4.0),
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 4.0),
|
|
|
|
child: IconButton( //modified
|
|
|
|
child: IconButton(
|
|
|
|
|
|
|
|
//modified
|
|
|
|
icon: Icon(Icons.send),
|
|
|
|
icon: Icon(Icons.send),
|
|
|
|
onPressed: _isComposing ?
|
|
|
|
onPressed: _isComposing
|
|
|
|
() => _handleSubmitted(_textController.text) : null,
|
|
|
|
? () => _handleSubmitted(_textController.text)
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
],
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -218,7 +220,7 @@ class ChatScreenState extends State<ChatScreen> with TickerProviderStateMixin {
|
|
|
|
text: text,
|
|
|
|
text: text,
|
|
|
|
animationController: AnimationController(
|
|
|
|
animationController: AnimationController(
|
|
|
|
duration: Duration(milliseconds: 200),
|
|
|
|
duration: Duration(milliseconds: 200),
|
|
|
|
vsync: this
|
|
|
|
vsync: this,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
name: contactName,
|
|
|
|
name: contactName,
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -239,14 +241,14 @@ class ChatMessage extends StatelessWidget {
|
|
|
|
return SizeTransition(
|
|
|
|
return SizeTransition(
|
|
|
|
sizeFactor: CurvedAnimation(
|
|
|
|
sizeFactor: CurvedAnimation(
|
|
|
|
parent: animationController,
|
|
|
|
parent: animationController,
|
|
|
|
curve: Curves.easeOut
|
|
|
|
curve: Curves.easeOut,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
axisAlignment: 0.0,
|
|
|
|
axisAlignment: 0.0,
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(vertical: 10.0),
|
|
|
|
margin: const EdgeInsets.symmetric(vertical: 10.0),
|
|
|
|
child: Row(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.only(right: 16.0),
|
|
|
|
margin: const EdgeInsets.only(right: 16.0),
|
|
|
|
child: CircleAvatar(child: Text(name[0])),
|
|
|
|
child: CircleAvatar(child: Text(name[0])),
|
|
|
@ -254,7 +256,7 @@ class ChatMessage extends StatelessWidget {
|
|
|
|
Expanded(
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
children: [
|
|
|
|
Text(name, style: Theme.of(context).textTheme.subhead),
|
|
|
|
Text(name, style: Theme.of(context).textTheme.subhead),
|
|
|
|
Container(
|
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.only(top: 5.0),
|
|
|
|
margin: const EdgeInsets.only(top: 5.0),
|
|
|
@ -265,7 +267,7 @@ class ChatMessage extends StatelessWidget {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|