Skip to content

Instantly share code, notes, and snippets.

View hjJunior's full-sized avatar

Helio S. Junior hjJunior

View GitHub Profile
class MyIp {
final _client = Client();
Future<String> get ipAddress async {
final apiResult = await _client.get('https://api.ipify.org/?format=json');
return json.decode(apiResult.body)['ip'];
}
}
class MyIp {
MyIp(this._client);
final Client _client;
Future<String> get ipAddress async {
final apiResult = await _client.get('https://api.ipify.org/?format=json');
return json.decode(apiResult.body)['ip'];
}
}
import 'dart:async';
import 'package:sqflite/sqflite.dart';
import 'package:reflectable/reflectable.dart';
Database db;
/// A Model abstract class
abstract class Model<T> {
static String primaryKey;
static String table;
@hjJunior
hjJunior / jwt-payload-parse.dart
Created January 15, 2019 18:00
Get payload of JWT token in Dart language
import 'dart:convert';
Map<String, dynamic> parseJwt(String token) {
final parts = token.split('.');
if (parts.length != 3) {
throw Exception('invalid token');
}
final payload = _decodeBase64(parts[1]);
final payloadMap = json.decode(payload);
import 'package:flutter/material.dart';
import '../models/beer.dart';
class BeerTile extends StatelessWidget {
final Beer _beer;
BeerTile(this._beer);
@override
Widget build(BuildContext context) => Column(
children: <Widget>[
...
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Top Beers'),
),
body: ListView.builder(
itemCount: _beers.length,
import '../repository/beer_repository.dart';
import '../models/beer.dart';
...
class _HomeState extends State<Home> {
List<Beer> _beers = <Beer>[];
@override
void initState() {
import 'package:http/http.dart' as http;
import 'dart:convert';
import '../models/beer.dart';
Future<Stream<Beer>> getBeers() async {
final String url = 'https://api.punkapi.com/v2/beers';
final client = new http.Client();
final streamedRest = await client.send(
http.Request('get', Uri.parse(url))
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http: ^0.12.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
@hjJunior
hjJunior / beer.dart
Created December 10, 2018 12:41
Beer model
class Beer {
final int id;
final String name;
final String tagline;
final String description;
final String image_url;
Beer.fromJSON(Map<String, dynamic> jsonMap) :
id = jsonMap['id'],
name = jsonMap['name'],