1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-10 14:58:34 +00:00

Add analysis_options, re-format, add commas. (#101)

This commit is contained in:
Brett Morgan
2019-07-03 08:08:35 +10:00
committed by GitHub
parent 45e4a228f5
commit 4f72ab1776
8 changed files with 94 additions and 61 deletions

View File

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