Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import "package:flutter/material.dart";
  2. import 'package:news/Article.dart';
  3.  
  4. class NewsState extends State<NewsList> {
  5. final _articles = <Article>[];
  6. final _biggerFont = const TextStyle(fontSize: 18.0);
  7.  
  8. Widget _buildArticles() {
  9. return ListView.builder(
  10. padding: const EdgeInsets.all(16.0),
  11. itemBuilder: buildListItem,
  12. );
  13. }
  14.  
  15. Widget buildListItem(BuildContext context, int i) {
  16. if (i.isOdd) return Divider();
  17.  
  18. int index = i ~/ 2;
  19. if (index >= _articles.length) {
  20. _fetchArticles();
  21. index = _articles.length;
  22. }
  23.  
  24. return _buildRow(_articles[i]);
  25. }
  26.  
  27. Widget _buildRow(Article article) {
  28. return ListTile(
  29. title: Text(article.title, style: _biggerFont)
  30. );
  31. }
  32.  
  33. void _fetchArticles() {
  34. //TODO: Fetch new articles using fetch endpoint
  35. for (var i = 0; i < 50; i++) {
  36. _articles.add(new Article.fromIndex(i));
  37. }
  38. }
  39.  
  40. @override
  41. Widget build(BuildContext context) {
  42.  
  43. //TODO: load from latest
  44. for (var i = 0; i < 50; i++) {
  45. _articles.add(new Article.fromIndex(i));
  46. }
  47.  
  48. return Scaffold(
  49. appBar: AppBar(
  50. title: Text("Actualtés"),
  51. ),
  52. body: _buildArticles(),
  53. );
  54. }
  55. }
  56.  
  57. class NewsList extends StatefulWidget {
  58. @override
  59. NewsState createState() => NewsState();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement