diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index f209be0..7dbc828 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -54,5 +54,7 @@ io.flutter.embedded_views_preview + CADisableMinimumFrameDurationOnPhone + diff --git a/lib/api/api.dart b/lib/api/api.dart index 3a6df6a..b941a39 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -357,6 +357,25 @@ class _APIRequests { return new helpers.ListResource.load("articles", params); } + Future> getHomescreenNews() async { + await _actionExecution(APIAction.GET_ARTICLE); + Map params = {}; + params['limit'] = 3.toString(); + params['tags'] = "eq-5uxbYvmfyVLejcyMSD4lMu"; + params['orderby'] = "desc-priority,desc-changed"; + params['view'] = "preview-with-image"; + + String response = await http.getFromAPI("articles", params, null); + //print(response); + var jsonResponse = jsonDecode(response)["entities"]; + //if (!jsonResponse.containsKey('entities')) return null; + List articles = []; + for (var entity in jsonResponse) { + articles.add(new models.Article.fromJSON(entity)); + } + return articles; + } + Future getArticle(String id) async { await _actionExecution(APIAction.GET_ARTICLE); @@ -379,7 +398,9 @@ class _APIRequests { if (_api._authenticationUser.isLoggedIn() && _api._userData.isOberstufe) { exams = await _getUpcomingExams(); } - return helpers.HomeScreenData(termine, ferien, exams); + List news = await getHomescreenNews(); + //models.Termin ferien = await _getNextFerienEvent(); + return helpers.HomeScreenData(termine, ferien, exams, news); } Future getMailSettings() async { diff --git a/lib/api/api_helpers.dart b/lib/api/api_helpers.dart index f8dd2dd..60a65f4 100644 --- a/lib/api/api_helpers.dart +++ b/lib/api/api_helpers.dart @@ -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; @@ -136,11 +137,12 @@ Map getDecodedJWT(String jwt) { } class HomeScreenData { - HomeScreenData(this.termine, this.countdown, this.exams); + HomeScreenData(this.termine, this.countdown, this.exams, this.news); final List termine; final Termin countdown; final List exams; + final List
news; DateTime get ferienDatetime => countdown.startDatetime; } diff --git a/lib/components/home.dart b/lib/components/home.dart index d0d164b..2bd1495 100644 --- a/lib/components/home.dart +++ b/lib/components/home.dart @@ -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'; @@ -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 { @@ -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), ], ); } @@ -225,6 +231,151 @@ class ShortcutsWidget extends StatelessWidget { } +class NewsWidget extends StatelessWidget { + final HomeScreenData homeScreenData; + NewsWidget(this.homeScreenData, {Key key}) : super(key: key); + + @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, + ), + ListView.builder( + scrollDirection: Axis.horizontal, + shrinkWrap: true, + itemCount: 3, + itemBuilder: (context, index) { + return NewsListItem(homeScreenData.news[index]); + }, + ) + ] + ); + } +} + +class NewsListItem extends StatelessWidget { + const NewsListItem(this.news); + + final Article news; + + @override + Widget build(BuildContext context) { + return + Container( + margin: EdgeInsets.all(20), + clipBehavior: Clip.hardEdge, + decoration: BoxDecoration( + color: Color.fromARGB(33, 0, 0, 0), + borderRadius: BorderRadius.all(Radius.circular(25)) + ), + child: Column( + children: [ + if(news.hasImage) Image(image: CachedNetworkImageProvider("https://${api_raw.API}/files/${news.imageID}")), + 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});