Skip to content

Instantly share code, notes, and snippets.

Avatar

Dhiraj Sharma sharmadhiraj

View GitHub Profile
View flutter_infinite_scroll_main_3.dart
Widget getBody() {
if (_photos.isEmpty) {
if (_loading) {
return Center(
child: Padding(
padding: const EdgeInsets.all(8),
child: CircularProgressIndicator(),
));
} else if (_error) {
return Center(
View flutter_infinite_scroll_main_2.dart
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);
View flutter_infinite_scroll_main_1.dart
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;
View main.dart
//...........................................
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:
View main.dart
//...........................................
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.");
}
View main.dart
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
View BaseActivity.java
public abstract class BaseActivity extends AppCompatActivity {
private AlertDialog dialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
connectToFirebase();
}
View UnderMaintenance.java
public class UnderMaintenance {
public boolean is_under_maintenance;
public String under_maintenance_message;
public UnderMaintenance() {
}
}
@sharmadhiraj
sharmadhiraj / vue_axios_example.html
Created Jan 2, 2019
Vue.js | Making API calls using Axios
View vue_axios_example.html
<!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>
@sharmadhiraj
sharmadhiraj / base.dart
Created Aug 9, 2018
Base StatefulWidget
View base.dart
abstract class BaseStatefulWidget extends StatefulWidget {
String getTitle();
Widget body(AsyncSnapshot snapshot);
Future future();
@override
State<StatefulWidget> createState() => BaseState(getTitle());
}