Skip to content

Instantly share code, notes, and snippets.

View jesusrp98's full-sized avatar
🏠
Working from home

Jesús Rodríguez jesusrp98

🏠
Working from home
View GitHub Profile
@jesusrp98
jesusrp98 / launchpad.dart
Created January 9, 2019 19:21
Launchpad model using ScopedModel
class LaunchpadModel extends QuerryModel {
final String id, name;
LaunchpadModel(this.id, this.name);
@override
Future loadData() async {
// Get item by http call
response = await http.get(Url.launchpadDialog + id);
@jesusrp98
jesusrp98 / querry_model.dart
Created January 9, 2019 19:33
General model used to help retrieve, parse & storage information from a public API
import 'dart:async';
import 'package:scoped_model/scoped_model.dart';
/// QUERRY MODEL
/// General model used to help retrieve, parse & storage
/// information from a public API
abstract class QuerryModel extends Model {
List _items = List();
List _photos = List();
@jesusrp98
jesusrp98 / page_rocket.dart
Created January 9, 2019 19:47
Example of Slivers & Swipers on the rocket's page
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(slivers: <Widget>[
SliverAppBar(
expandedHeight: MediaQuery.of(context).size.height * 0.3,
floating: false,
pinned: true,
actions: <Widget>[
// ...
@jesusrp98
jesusrp98 / i18n_example.dart
Created January 9, 2019 21:41
Example of flutter_i18n pacakge
// assets/flutter_i18n/en.json
// {
// "foo": {
// "bar": "Sample",
// // ...
// },
// // ...
// }
Text(
@jesusrp98
jesusrp98 / cache_image.dart
Created January 10, 2019 12:14
Auxiliary widget to display a cached image. It has its own 'error' widget.
return CachedNetworkImage(
imageUrl: url,
errorWidget: Icon(
Icons.cancel,
size: 32.0,
color: Theme.of(context).textTheme.caption.color,
),
fadeInDuration: Duration(milliseconds: 100),
fit: BoxFit.cover,
);
@jesusrp98
jesusrp98 / search_launches.dart
Created January 10, 2019 12:20
Auxiliary method which helps filter launches by its name
searchLaunches(BuildContext context, List list) {
return MaterialPageRoute<Launch>(
builder: (context) => Material(
child: MaterialSearch<Launch>(
barBackgroundColor: Theme.of(context).primaryColor,
iconColor: Colors.white,
placeholder: FlutterI18n.translate(
context,
'spacex.other.tooltip.search',
),
@jesusrp98
jesusrp98 / pubspec.yaml
Last active April 19, 2019 12:05
Pubspec file with notification's package
dependencies:
flutter:
sdk: flutter
...
flutter_local_notifications: ^0.6.1
@jesusrp98
jesusrp98 / AndroidManifest.xml
Last active April 19, 2019 12:05
Android manifest including notification's changes
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application>
<activity>
...
</activity>
@jesusrp98
jesusrp98 / initNotifications.dart
Created April 16, 2019 19:06
Schedules notifications if neccesary
Future initNotifications(BuildContext context) async {
bool updateNotifications;
final SharedPreferences prefs = await SharedPreferences.getInstance();
// Checks if is necessary to update scheduled notifications
try {
updateNotifications =
prefs.getString('notifications.launches.upcoming') !=
launch.launchDate.toIso8601String();
} catch (e) {
@jesusrp98
jesusrp98 / scheduleNotification.dart
Created April 16, 2019 19:07
Function that actually schedules a notification
Future _scheduleNotification({
BuildContext context,
int id,
String time,
Duration subtract,
}) async {
await ScopedModel.of<AppModel>(context).notifications.schedule(
id,
FlutterI18n.translate(context, 'spacex.notifications.launches.title'),
FlutterI18n.translate(