import 'package:flutter/cupertino.dart'; import 'package:hiddingsel_app/appflow/controller/articles.dart'; import 'package:hiddingsel_app/appflow/model/represented_organisations.dart'; import 'package:hiddingsel_app/appflow/view/navigation_drawer.dart'; import '../../model/articles.dart'; import '../further_pages/article.dart'; class ArticleListView extends StatelessWidget with NavigationDrawerItem{ final String title; final Stream> _articleStream; final Function(PreferredSizeWidget appBar, Widget body)? _onChange; ArticleListView(this._onChange) : title = 'News', _articleStream = ArticleController.getArticleListStream(); ArticleListView.favorites(this._onChange) : title = 'Favoriten', _articleStream = ArticleController.getFavoriteArticleListStream(); ArticleListView.search(String searchWord, this._onChange) : title = 'Suche', _articleStream = ArticleController.getSearchResultListStream(searchWord); ArticleListView.organisation(RepresentedOrganisationModel organisation, this._onChange, {scrollController}) : title = 'Organisation', _articleStream = ArticleController.getOrganisationArticleListStream(organisation); @override Widget build(BuildContext context) => StreamBuilder( initialData: List.empty(), stream: _articleStream, builder: (context, AsyncSnapshot> snapshot) => buildArticleListView(context, snapshot.data??[]) ); Widget buildArticleListView(BuildContext context, List list) => ListView.builder( itemCount: list.length, itemBuilder: (context, index) => ArticleThumbnailView(list[index], _onChange), ); }