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
Widget getBody() { | |
if (_photos.isEmpty) { | |
if (_loading) { | |
return Center( | |
child: Padding( | |
padding: const EdgeInsets.all(8), | |
child: CircularProgressIndicator(), | |
)); | |
} else if (_error) { | |
return Center( |
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
Future<void> fetchPhotos() async { | |
try { | |
final response = await http.get( | |
"https://jsonplaceholder.typicode.com/photos?_page=$_pageNumber"); | |
List<Photo> fetchedPhotos = Photo.parseList(json.decode(response.body)); | |
setState(() { | |
_hasMore = fetchedPhotos.length == _defaultPhotosPerPageCount; | |
_loading = false; | |
_pageNumber = _pageNumber + 1; | |
_photos.addAll(fetchedPhotos); |
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
class PhotosListScreen extends StatefulWidget { | |
PhotosListScreen({Key key}) : super(key: key); | |
@override | |
_PhotosListScreenState createState() => _PhotosListScreenState(); | |
} | |
class _PhotosListScreenState extends State<PhotosListScreen> { | |
bool _hasMore; | |
int _pageNumber; | |
bool _error; | |
bool _loading; |
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
class NewsListActivity : AppCompatActivity() { | |
private lateinit var viewModel: NewsListViewModel | |
private lateinit var newsListAdapter: NewsListAdapter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_news_list) | |
viewModel = ViewModelProviders.of(this) |
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
//Kotlin | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
//Support | |
implementation 'androidx.appcompat:appcompat:1.0.2' | |
implementation 'com.google.android.material:material:1.0.0' | |
implementation 'androidx.recyclerview:recyclerview:1.0.0' | |
implementation 'androidx.cardview:cardview:1.0.0' | |
//Architecture Components |
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
<!DOCTYPE html> | |
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Vue.js | Making API calls using Axios</title> | |
</head> | |
<body style="text-align: center"> | |
<div id="app" style="display: inline-block;margin-top: 100px"> | |
<img v-bind:src="avatar" alt=""> | |
<h1 style="margin-bottom: 0">{{name}}</h1> |
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
//........................................... | |
body: FutureBuilder<String>( | |
future: fetchJoke(), | |
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | |
switch (snapshot.connectionState) { | |
case ConnectionState.none: | |
case ConnectionState.active: | |
case ConnectionState.waiting: | |
return Center(child: CircularProgressIndicator()); | |
case ConnectionState.done: |
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
//........................................... | |
Future<String> fetchJoke() async { | |
var url = "https://api.chucknorris.io/jokes/random?category=dev"; | |
var response = await http.get(url); | |
if (response.statusCode == 200) { | |
var jsonResponse = convert.jsonDecode(response.body); | |
return jsonResponse['value']; | |
} else { | |
return ("Unexpected error occurred."); | |
} |
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_web/material.dart'; | |
void main() => runApp(App()); | |
class App extends MaterialApp { | |
@override | |
String get title => "Chuck Norris Jokes"; | |
@override | |
ThemeData get theme => ThemeData(primarySwatch: Colors.blue); | |
@override |
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
public abstract class BaseActivity extends AppCompatActivity { | |
private AlertDialog dialog; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
connectToFirebase(); | |
} |
NewerOlder