Skip to content

Commit

Permalink
email preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Rody Davis committed Mar 14, 2019
1 parent 04142c8 commit b1d546a
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 6 deletions.
16 changes: 16 additions & 0 deletions assets/email_preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# gmail_clone

A new Flutter application to showcase how to build Gmail with Flutter.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.io/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.io/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.io/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
1 change: 1 addition & 0 deletions lib/ui/common/common.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export 'email_fab.dart';
export 'email_tile.dart';
export 'email_view.dart';
74 changes: 74 additions & 0 deletions lib/ui/common/email_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gmail_clone/data/classes/email.dart';

import 'package:flutter_markdown/flutter_markdown.dart';

class EmailView extends StatefulWidget {
EmailView({
@required this.item,
this.favoriteChanged,
});

final EmailItem item;
final VoidCallback favoriteChanged;

@override
_EmailViewState createState() => _EmailViewState();
}

class _EmailViewState extends State<EmailView> {
String _preview;

@override
void initState() {
rootBundle.loadString("assets/email_preview.md").then((data) {
setState(() {
print("Data: $data");
_preview = data;
});
});
super.initState();
}

@override
Widget build(BuildContext context) {
if (_preview == null) {
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
}

return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.all(12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Text(
widget.item?.title ?? "",
maxLines: 2,
style: Theme.of(context).textTheme.title,
),
),
IconButton(
icon: (widget.item?.favorite ?? false)
? Icon(Icons.star, color: Colors.amber)
: Icon(Icons.star_border),
onPressed: widget.favoriteChanged,
),
],
),
),
Expanded(
child: Markdown(data: _preview),
),
],
);
}
}
19 changes: 13 additions & 6 deletions lib/ui/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class _HomeScreenState extends State<HomeScreen> {
Widget build(BuildContext context) {
return ResponsiveScaffold.builder(
detailBuilder: (BuildContext context, int index) {
final i = _emails[index];
return DetailsScreen(
appBar: AppBar(
elevation: 0.0,
Expand All @@ -33,7 +34,11 @@ class _HomeScreenState extends State<HomeScreen> {
),
IconButton(
icon: Icon(Icons.delete_outline),
onPressed: () {},
onPressed: () {
setState(() {
_emails.removeAt(index);
});
},
),
IconButton(
icon: Icon(Icons.mail_outline),
Expand All @@ -45,10 +50,13 @@ class _HomeScreenState extends State<HomeScreen> {
),
],
),
body: Container(
child: Center(
child: Text("Item: $index"),
),
body: EmailView(
item: i,
favoriteChanged: () {
setState(() {
i.favorite = !i.favorite;
});
},
),
);
},
Expand Down Expand Up @@ -76,7 +84,6 @@ class _HomeScreenState extends State<HomeScreen> {
itemBuilder: (BuildContext context, int index) {
final i = _emails[index];
final bool _lastItem = (index + 1) == emails?.length ?? 0;
print("$index => ${emails?.length}");
if (_lastItem) {
return Container(
padding: EdgeInsets.only(bottom: 70.0),
Expand Down
21 changes: 21 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
packages:
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.1"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -48,6 +55,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_markdown:
dependency: "direct main"
description:
name: flutter_markdown
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -60,6 +74,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.7"
markdown:
dependency: transitive
description:
name: markdown
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
matcher:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ dependencies:
responsive_scaffold: ^0.0.1
floating_search_bar: ^0.1.2
intl: ^0.15.7
flutter_markdown: ^0.2.0

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
assets:
- assets/email_preview.md

0 comments on commit b1d546a

Please sign in to comment.