Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startseite news #187

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,26 @@ class _APIRequests {
return new helpers.ListResource<models.Article>.load("articles", params);
}

Future<List<models.Article>> getHomescreenNews() async {
// Not calling actionExecution here, because login not needed and needs async
Map<String, String> params = {};
params['limit'] = 3.toString();
params['tags'] = "eq-5uxbYvmfyVLejcyMSD4lMu";
params['orderby'] = "desc-priority,desc-changed";

String response = await http.getFromAPI("articles", params, null);
print(response);
var jsonResponse = jsonDecode(response)["entities"];
print(jsonResponse);
//if (!jsonResponse.containsKey('entities')) return null;
List<models.Article> articles = [];
for (var entity in jsonResponse) {
print(entity);
articles.add(new models.Article.fromJSON(entity));
}
return articles;
}

Future<models.Article> getArticle(String id) async {
await _actionExecution(APIAction.GET_ARTICLE);

Expand All @@ -379,7 +399,9 @@ class _APIRequests {
if (_api._authenticationUser.isLoggedIn() && _api._userData.isOberstufe) {
exams = await _getUpcomingExams();
}
return helpers.HomeScreenData(termine, ferien, exams);
List<models.Article> news = await getHomescreenNews();
//models.Termin ferien = await _getNextFerienEvent();
return helpers.HomeScreenData(termine, ferien, exams, news);
}

Future<models.MailSettings> getMailSettings() async {
Expand Down
4 changes: 3 additions & 1 deletion lib/api/api_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';

import 'package:flutter/material.dart';

import '../Views/News.dart';
import 'api.dart';
import 'api_models.dart';
import 'api_raw.dart' show getFromAPI;
Expand Down Expand Up @@ -136,11 +137,12 @@ Map<dynamic, dynamic> getDecodedJWT(String jwt) {
}

class HomeScreenData {
HomeScreenData(this.termine, this.countdown, this.exams);
HomeScreenData(this.termine, this.countdown, this.exams, this.news);

final List<Termin> termine;
final Termin countdown;
final List<Exam> exams;
final List<Article> news;

DateTime get ferienDatetime => countdown.startDatetime;
}
Expand Down
144 changes: 143 additions & 1 deletion lib/components/home.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'dart:html';

import 'package:flutter/foundation.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
Expand All @@ -10,6 +13,7 @@ import '../api/api_models.dart';
import 'helpers.dart';
import 'menu.dart';
import 'terminlist.dart';
import '../api/api_raw.dart' as api_raw;

/// Chooses if the Mobile or TabletWidget is needed
class SurroundingWidget extends StatelessWidget {
Expand Down Expand Up @@ -124,7 +128,9 @@ class HomeList extends StatelessWidget {
ShortcutsWidget(isTablet: isTablet),
// Only show Impressum on web
if (kIsWeb) splittingContainer,
if (kIsWeb) ImpressumWidget()
if (kIsWeb) ImpressumWidget(),
splittingContainer,
NewsWidget(homeScreenData: homeScreenData),
],
);
}
Expand Down Expand Up @@ -225,6 +231,142 @@ class ShortcutsWidget extends StatelessWidget {

}

class NewsWidget extends StatelessWidget {
final HomeScreenData homeScreenData;
NewsWidget({Key key, this.homeScreenData}) : super(key: key);

//News news;

@override
Widget build(BuildContext context) {
return Column(
//color: Colors.pink,
children: [
Container(
child: Text("News", style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold)),
margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
alignment: Alignment.centerLeft,
)
]..addAll(homeScreenData.news.map((news) => NewsListItem(news))),
);
}
}

class NewsListItem extends StatelessWidget {
const NewsListItem(this.news);

final Article news;

@override
Widget build(BuildContext context) {
return
Container(
margin: EdgeInsets.all(2),
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Color.fromARGB(47, 0, 0, 0),
),
borderRadius: BorderRadius.all(Radius.circular(16))
),
child: ListTile(
title: Text(news.title, style: TextStyle(fontSize: 24)),
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (context) => ArticleDetail(news))),
),
);
}
}

class ImageBox extends StatelessWidget {
final Article article;

ImageBox(this.article);

@override
Widget build(BuildContext context) {
return Visibility(
visible: article.hasImage,
child: Align(
alignment: Alignment.bottomCenter,
child: new Container(
height: 230,
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.fitWidth,
alignment: FractionalOffset.center,
image: CachedNetworkImageProvider("https://${api_raw.API}/files/${article.imageID}")
)
),
)
),
);
}
}

class ArticleCard extends StatelessWidget {
ArticleCard(this.article);

final Article article;

@override
Widget build(BuildContext context) {
return Container(
width: 100,
margin: EdgeInsets.all(20),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
elevation: 1,
child: InkWell(
child: Stack(
children: [
ImageBox(article),
TitleBox(article)
],
),
splashColor: Color.fromRGBO(47, 109, 29, 1),
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => ArticleDetail(article))),
),
),
);
}
}

class TitleBox extends StatelessWidget {
final Article article;
static const titleStyle = const TextStyle(fontSize: 30, fontWeight: FontWeight.bold, color: Colors.white, letterSpacing: 0.5);

TitleBox(this.article);

@override
Widget build(BuildContext context) {
return Positioned.fill(child: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: double.infinity,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color.fromRGBO(47, 47, 47, 0), Color.fromRGBO(47, 47, 47, 0.3), Color.fromRGBO(47, 47, 47, 0.6), Color.fromRGBO(47, 47, 47, 0.8)],
),
),
padding: EdgeInsets.fromLTRB(10, 2, 10, 2),
child: Padding(
padding: EdgeInsets.fromLTRB(0, 50, 0, 0),
child: Text(article.title, style: titleStyle, textAlign: TextAlign.left)
)
),
),
));
}


}

class FerienCountdown extends StatelessWidget {
const FerienCountdown(this.homeScreenData, {this.isTablet = false});

Expand Down