Skip to content

Commit

Permalink
✨ Use short title in AppBar in ArticleDetail (#143)
Browse files Browse the repository at this point in the history
We now show the article short title in the AppBar instead
of the "News" text.

Resolve #136
  • Loading branch information
Phantom061 authored Mar 29, 2022
1 parent 4c6322e commit dda2a92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/api/api_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,25 @@ class KAGUser {
}

class Article {
String _title, _id, _htmlBody;
String _title, _id, _htmlBody, _shortTitle;
Map<String, String> _image;

Article(this._id, this._title, this._htmlBody, this._image);
Article(this._id, this._title, this._htmlBody, this._shortTitle, this._image);

Article.fromJSON(Map<dynamic, dynamic> rawJSON) {
if (rawJSON.containsKey("id")) _id = rawJSON['id'];
if (rawJSON.containsKey("title")) _title = rawJSON['title'];
if (rawJSON.containsKey("body")) _htmlBody = utf8.decode(base64Decode(rawJSON['body'].replaceAll('\n', '')));
if (rawJSON.containsKey("files") && rawJSON['files'] is Map) _image = new Map<String, String>.from(rawJSON['files']);
if (rawJSON.containsKey("short_title")) _shortTitle = rawJSON['short_title'];
}

// Image stuff
String get imageID => _image != null ? _image['id'] : null;
bool get hasImage => _image != null;

String get title => _title;
String get shortTitle => _shortTitle;
String get id => _id;
String get htmlBody => _htmlBody;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/components/news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ class ArticleDetailWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
var htmlData = """<h1>${article.title}</h1><br><br> ${article.htmlBody != null ? article.htmlBody : ""}""";
var htmlData = """${article.htmlBody != null ? article.htmlBody : ""}""";
return Scaffold(
appBar: AppBar(
title: Text("News"),
title: Text(article.shortTitle != "" ? article.shortTitle : article.title),
),
body: Container(
child: ListView(
children: <Widget>[Html(data: htmlData, onLinkTap: launch)],
),
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
padding: EdgeInsets.fromLTRB(10, 4, 10, 0),
),
);
}
Expand Down

0 comments on commit dda2a92

Please sign in to comment.