Created
October 25, 2019 19:58
-
-
Save HamedTaherpour/5a954b29a6c11d2f9ee7f500abbd0b29 to your computer and use it in GitHub Desktop.
Sample app in flutter: Listview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:url_launcher/url_launcher.dart'; | |
import 'src/article.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
List<Article> _articles = articles; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: RefreshIndicator( | |
onRefresh: () async { | |
await new Future.delayed(const Duration(seconds: 1)); | |
setState(() { | |
_articles.removeAt(0); | |
}); | |
}, | |
child: ListView( | |
children: _articles.map(builderItem).toList(), | |
), | |
), | |
); | |
} | |
Widget builderItem(Article article) { | |
return Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: new ExpansionTile( | |
title: new Text( | |
article.text, | |
style: new TextStyle(fontSize: 24.0), | |
), | |
children: [ | |
new Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
new Text('${article.commentsCount} commnents'), | |
new IconButton( | |
icon: new Icon(Icons.launch), | |
onPressed: () async { | |
final fakeUrl = 'https://${article.domain}'; | |
if (await canLaunch(fakeUrl)) { | |
launch(fakeUrl); | |
} | |
}, | |
) | |
], | |
) | |
], | |
), | |
); | |
} | |
} | |
class Article { | |
const Article({ | |
this.text, | |
this.domain, | |
this.by, | |
this.age, | |
this.score, | |
this.commentsCount, | |
}); | |
final String text; | |
final String domain; | |
final String by; | |
final int age; | |
final int score; | |
final int commentsCount; | |
} | |
final List<Article> articles = <Article>[ | |
Article( | |
text: 'Tom Hardy', | |
domain: 'google.com', | |
by: 'Tom Hardy', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Johnny Depp', | |
domain: 'google.com', | |
by: 'Johnny Depp', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Tom Cruise', | |
domain: 'google.com', | |
by: 'Tom Cruise', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Keira Knightley', | |
domain: 'google.com', | |
by: 'Keira Knightley', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Robert De Niro', | |
domain: 'google.com', | |
by: 'Robert De', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Leonardo DiCaprio', | |
domain: 'google.com', | |
by: 'Leonardo DiCaprio', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Will Smith', | |
domain: 'google.com', | |
by: 'Will Smith', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Russell Crowe', | |
domain: 'google.com', | |
by: 'Russell Crowe', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Brad Pitt', | |
domain: 'google.com', | |
by: 'Brad Pitt', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Angelina Jolie', | |
domain: 'google.com', | |
by: 'Angelina Jolie', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Kate Winslet', | |
domain: 'google.com', | |
by: 'Kate Winslet', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Christian Bale', | |
domain: 'google.com', | |
by: 'Christian Bale', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Morgan Freeman', | |
domain: 'google.com', | |
by: 'Morgan Freeman', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Hugh Jackman', | |
domain: 'google.com', | |
by: 'Hugh Jackman', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Keanu Reeves', | |
domain: 'google.com', | |
by: 'Keanu Reeves', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Tom Hanks', | |
domain: 'google.com', | |
by: 'Tom Hanks', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Scarlett Johansson', | |
domain: 'google.com', | |
by: 'Scarlett Johansson', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
), | |
Article( | |
text: 'Robert Downey Jr.', | |
domain: 'google.com', | |
by: 'Robert Downey', | |
age: 5, | |
score: 123, | |
commentsCount: 321, | |
) | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment