Skip to content

Commit

Permalink
Merge pull request #2 from CodemateLtd/feature/migrate-to-dart-2
Browse files Browse the repository at this point in the history
Migrate to dart 2 & minor cleanup
  • Loading branch information
roughike committed Apr 23, 2018
2 parents 73f7957 + 0338dc9 commit 591cd6f
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 120 deletions.
4 changes: 2 additions & 2 deletions lib/main.dart
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_mates/ui/friends/friends_page.dart';
import 'package:flutter_mates/ui/friends/friends_list_page.dart';

void main() {
runApp(new MyApp());
Expand All @@ -13,7 +13,7 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue,
accentColor: const Color(0xFFF850DD),
),
home: new FriendsPage(),
home: new FriendsListPage(),
);
}
}
4 changes: 2 additions & 2 deletions lib/ui/frienddetails/footer/friend_detail_footer.dart
Expand Up @@ -20,7 +20,7 @@ class _FriendShowcaseState extends State<FriendShowcase>
TabController _controller;

@override
initState() {
void initState() {
super.initState();
_tabs = [
new Tab(text: 'Portfolio'),
Expand All @@ -43,7 +43,7 @@ class _FriendShowcaseState extends State<FriendShowcase>
return new Padding(
padding: const EdgeInsets.all(16.0),
child: new Column(
children: [
children: <Widget>[
new TabBar(
controller: _controller,
tabs: _tabs,
Expand Down
16 changes: 10 additions & 6 deletions lib/ui/frienddetails/footer/portfolio_showcase.dart
@@ -1,20 +1,24 @@
import 'package:flutter/material.dart';

class PortfolioShowcase extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<Widget> _buildItems() {
var items = <Widget>[];

for (var i = 1; i <= 6; i++) {
var image = new Image.asset(
'images/portfolio_$i.jpeg',
width: 200.0,
height: 200.0,
'images/portfolio_$i.jpeg',
width: 200.0,
height: 200.0,
);

items.add(image);
}

return items;
}

@override
Widget build(BuildContext context) {
var delegate = new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8.0,
Expand All @@ -24,7 +28,7 @@ class PortfolioShowcase extends StatelessWidget {
return new GridView(
padding: const EdgeInsets.only(top: 16.0),
gridDelegate: delegate,
children: items,
children: _buildItems(),
);
}
}
6 changes: 3 additions & 3 deletions lib/ui/frienddetails/footer/skills_showcase.dart
Expand Up @@ -7,9 +7,9 @@ class SkillsShowcase extends StatelessWidget {

return new Center(
child: new Text(
'Skills: TODO',
style: textTheme.title.copyWith(color: Colors.white),
'Skills: TODO',
style: textTheme.title.copyWith(color: Colors.white),
),
);
}
}
}
45 changes: 23 additions & 22 deletions lib/ui/frienddetails/friend_detail_body.dart
Expand Up @@ -3,10 +3,28 @@ import 'package:flutter_mates/ui/friends/friend.dart';

class FriendDetailBody extends StatelessWidget {
FriendDetailBody(this.friend);

final Friend friend;

_createCircleBadge(IconData iconData, Color color) {
Widget _buildLocationInfo(TextTheme textTheme) {
return new Row(
children: <Widget>[
new Icon(
Icons.place,
color: Colors.white,
size: 16.0,
),
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
friend.location,
style: textTheme.subhead.copyWith(color: Colors.white),
),
),
],
);
}

Widget _createCircleBadge(IconData iconData, Color color) {
return new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new CircleAvatar(
Expand All @@ -26,33 +44,16 @@ class FriendDetailBody extends StatelessWidget {
var theme = Theme.of(context);
var textTheme = theme.textTheme;

var locationInfo = new Row(
children: [
new Icon(
Icons.place,
color: Colors.white,
size: 16.0,
),
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
friend.location,
style: textTheme.subhead.copyWith(color: Colors.white),
),
),
],
);

return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
children: <Widget>[
new Text(
friend.name,
style: textTheme.headline.copyWith(color: Colors.white),
),
new Padding(
padding: const EdgeInsets.only(top: 4.0),
child: locationInfo,
child: _buildLocationInfo(textTheme),
),
new Padding(
padding: const EdgeInsets.only(top: 16.0),
Expand All @@ -67,7 +68,7 @@ class FriendDetailBody extends StatelessWidget {
new Padding(
padding: const EdgeInsets.only(top: 16.0),
child: new Row(
children: [
children: <Widget>[
_createCircleBadge(Icons.beach_access, theme.accentColor),
_createCircleBadge(Icons.cloud, Colors.white12),
_createCircleBadge(Icons.shop, Colors.white12),
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/frienddetails/friend_details_page.dart
Expand Up @@ -21,11 +21,11 @@ class FriendDetailsPage extends StatefulWidget {
class _FriendDetailsPageState extends State<FriendDetailsPage> {
@override
Widget build(BuildContext context) {
var linearGradient = new BoxDecoration(
gradient: new LinearGradient(
var linearGradient = const BoxDecoration(
gradient: const LinearGradient(
begin: FractionalOffset.centerRight,
end: FractionalOffset.bottomLeft,
colors: [
colors: <Color>[
const Color(0xFF413070),
const Color(0xFF2B264A),
],
Expand All @@ -38,7 +38,7 @@ class _FriendDetailsPageState extends State<FriendDetailsPage> {
decoration: linearGradient,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
children: <Widget>[
new FriendDetailHeader(
widget.friend,
avatarTag: widget.avatarTag,
Expand Down
80 changes: 45 additions & 35 deletions lib/ui/frienddetails/header/friend_detail_header.dart
Expand Up @@ -14,32 +14,10 @@ class FriendDetailHeader extends StatelessWidget {
final Friend friend;
final Object avatarTag;

_createPillButton(
String text, {
Color backgroundColor = Colors.transparent,
Color textColor = Colors.white70,
}) {
return new ClipRRect(
borderRadius: new BorderRadius.circular(30.0),
child: new MaterialButton(
minWidth: 140.0,
color: backgroundColor,
textColor: textColor,
onPressed: () {},
child: new Text(text),
),
);
}

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var textTheme = theme.textTheme;
var followerStyle =
textTheme.subhead.copyWith(color: const Color(0xBBFFFFFF));
Widget _buildDiagonalImageBackground(BuildContext context) {
var screenWidth = MediaQuery.of(context).size.width;

var diagonalBackground = new DiagonallyCutColoredImage(
return new DiagonallyCutColoredImage(
new Image.asset(
BACKGROUND_IMAGE,
width: screenWidth,
Expand All @@ -48,20 +26,27 @@ class FriendDetailHeader extends StatelessWidget {
),
color: const Color(0xBB8338f4),
);
}

var avatar = new Hero(
Widget _buildAvatar() {
return new Hero(
tag: avatarTag,
child: new CircleAvatar(
backgroundImage: new NetworkImage(friend.avatar),
radius: 50.0,
),
);
}

Widget _buildFollowerInfo(TextTheme textTheme) {
var followerStyle =
textTheme.subhead.copyWith(color: const Color(0xBBFFFFFF));

var followerInfo = new Padding(
return new Padding(
padding: const EdgeInsets.only(top: 16.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
children: <Widget>[
new Text('90 Following', style: followerStyle),
new Text(
' | ',
Expand All @@ -72,16 +57,18 @@ class FriendDetailHeader extends StatelessWidget {
],
),
);
}

var actionButtons = new Padding(
Widget _buildActionButtons(ThemeData theme) {
return new Padding(
padding: const EdgeInsets.only(
top: 16.0,
left: 16.0,
right: 16.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
children: <Widget>[
_createPillButton(
'HIRE ME',
backgroundColor: theme.accentColor,
Expand All @@ -99,18 +86,41 @@ class FriendDetailHeader extends StatelessWidget {
],
),
);
}

Widget _createPillButton(
String text, {
Color backgroundColor = Colors.transparent,
Color textColor = Colors.white70,
}) {
return new ClipRRect(
borderRadius: new BorderRadius.circular(30.0),
child: new MaterialButton(
minWidth: 140.0,
color: backgroundColor,
textColor: textColor,
onPressed: () {},
child: new Text(text),
),
);
}

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var textTheme = theme.textTheme;

return new Stack(
children: [
diagonalBackground,
children: <Widget>[
_buildDiagonalImageBackground(context),
new Align(
alignment: FractionalOffset.bottomCenter,
heightFactor: 1.4,
child: new Column(
children: [
avatar,
followerInfo,
actionButtons,
children: <Widget>[
_buildAvatar(),
_buildFollowerInfo(textTheme),
_buildActionButtons(theme),
],
),
),
Expand Down
11 changes: 7 additions & 4 deletions lib/ui/friends/friend.dart
Expand Up @@ -14,11 +14,14 @@ class Friend {
final String email;
final String location;

static List<Friend> allFromResponse(String json) {
return JSON
.decode(json)['results']
static List<Friend> allFromResponse(String response) {
var decodedJson = json.decode(response).cast<String, dynamic>();

return decodedJson['results']
.cast<Map<String, dynamic>>()
.map((obj) => Friend.fromMap(obj))
.toList();
.toList()
.cast<Friend>();
}

static Friend fromMap(Map map) {
Expand Down

0 comments on commit 591cd6f

Please sign in to comment.