Skip to content

Commit

Permalink
Dashboard : News article, News Details View, Share message
Browse files Browse the repository at this point in the history
  • Loading branch information
NirmalAriyathilake committed Mar 19, 2020
1 parent 81c1a7d commit 57a57c2
Showing 1 changed file with 210 additions and 35 deletions.
245 changes: 210 additions & 35 deletions lib/page/screen/dashboard_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:selftrackingapp/app_localizations.dart';
import 'package:selftrackingapp/models/news_article.dart';
import 'package:selftrackingapp/models/message_type.dart';
import 'package:selftrackingapp/notifiers/stories_model.dart';
import 'package:selftrackingapp/utils/tracker_colors.dart';
import 'package:share/share.dart';

import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../models/news_article.dart';
import '../../models/news_article.dart';
import '../../networking/api_client.dart';
import '../../utils/tracker_colors.dart';

Expand Down Expand Up @@ -109,6 +108,14 @@ class _DashboardScreenState extends State<DashboardScreen> {
});
}

void _shareArticle(NewsArticle article) {
Share.share("${article.title}\n\n"
"${article.subtitle}\n\n"
"by ${article.originator}\n"
"${dateFormat.format(article.created)}\n\n"
"${article.message}");
}

@override
Widget build(BuildContext context) {
print(Provider.of<StoriesModel>(context).articles.length);
Expand Down Expand Up @@ -258,6 +265,36 @@ class _DashboardScreenState extends State<DashboardScreen> {
Widget _createNewsArticle(NewsArticle article) {
print(
"${article.id} ${article.title},${article.message} ${article.created}");

Icon _icon = Icon(
Icons.info,
color: Colors.blue,
);

switch (article.messageType) {
case MessageType.Critical:
_icon = Icon(
Icons.report,
color: Colors.red,
size: 30.0,
);
break;
case MessageType.Warning:
_icon = Icon(
Icons.warning,
color: Colors.amber,
size: 30.0,
);
break;
case MessageType.Info:
_icon = Icon(
Icons.info,
color: Colors.blue,
size: 30.0,
);
break;
}

return Container(
padding: const EdgeInsets.all(10.0),
child: Card(
Expand All @@ -267,35 +304,59 @@ class _DashboardScreenState extends State<DashboardScreen> {
padding: const EdgeInsets.all(30.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
color: Color(TrackerColors.secondaryColor),
color: TrackerColors.primaryColor[100],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
width: 10.0,
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
Row(
children: <Widget>[
Text(
article.title,
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 15.0),
_icon,
SizedBox(
width: 15.0,
),
Expanded(
child: Text(
article.title,
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.title.copyWith(
fontWeight: FontWeight.bold,
),
),
),
Text(
"${article.created}",
//published data needs to facilitated into the messages from the API
textAlign: TextAlign.start,
style: TextStyle(color: Colors.black),
)
],
),
SizedBox(
height: 5,
),
Text(
article.subtitle,
textAlign: TextAlign.start,
style: Theme.of(context)
.textTheme
.title
.copyWith(fontWeight: FontWeight.normal),
),
SizedBox(
height: 5,
),
Text(
"by ${article.originator}",
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.body1,
),
Align(
alignment: Alignment.centerRight,
child: Text(
"${dateFormat.format(article.created)}",
//published data needs to facilitated into the messages from the API
style: Theme.of(context).textTheme.body1,
),
)
],
),
Expand All @@ -314,17 +375,25 @@ class _DashboardScreenState extends State<DashboardScreen> {
color: Colors.grey[400],
),
),
Align(
alignment: Alignment.centerLeft,
child: GestureDetector(
onTap: () {
Share.share("Shared button not implemented yet");
},
child: Icon(
Icons.share,
color: Colors.grey,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
onPressed: () {
_shareArticle(article);
},
icon: Icon(
Icons.share,
color: Colors.grey,
),
),
),
FlatButton(
child: Text("Read More"),
onPressed: () {
_showNewsArticle(article);
},
)
],
)
],
),
Expand All @@ -345,7 +414,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
borderRadius: BorderRadius.all(Radius.circular(20.0))),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
figure,
Expand All @@ -370,4 +439,110 @@ class _DashboardScreenState extends State<DashboardScreen> {
),
);
}

void _showNewsArticle(NewsArticle article) {
Icon _icon = Icon(
Icons.info,
color: Colors.blue,
);

switch (article.messageType) {
case MessageType.Critical:
_icon = Icon(
Icons.report,
color: Colors.red,
size: 30.0,
);
break;
case MessageType.Warning:
_icon = Icon(
Icons.warning,
color: Colors.amber,
size: 30.0,
);
break;
case MessageType.Info:
_icon = Icon(
Icons.info,
color: Colors.blue,
size: 30.0,
);
break;
}

showDialog(
context: context,
barrierDismissible: true,
builder: (_) {
return AlertDialog(
backgroundColor: Color(TrackerColors.secondaryColor),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
_icon,
SizedBox(
width: 15.0,
),
Expanded(
child: Text(
article.title,
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.title.copyWith(
fontWeight: FontWeight.bold,
),
),
),
],
),
SizedBox(
height: 5,
),
Text(
article.subtitle,
textAlign: TextAlign.start,
style: Theme.of(context)
.textTheme
.title
.copyWith(fontWeight: FontWeight.normal),
),
SizedBox(
height: 5,
),
Text(
"by ${article.originator}",
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.body1,
),
Align(
alignment: Alignment.centerRight,
child: Text(
"${dateFormat.format(article.created)}",
//published data needs to facilitated into the messages from the API
style: Theme.of(context).textTheme.body1,
),
)
],
),
content: Text(
article.message,
style: TextStyle(color: Colors.black),
),
actions: <Widget>[
IconButton(
onPressed: () {
_shareArticle(article);
},
icon: Icon(
Icons.share,
color: Colors.black,
),
),
],
);
});
}
}

0 comments on commit 57a57c2

Please sign in to comment.