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
// "estoy usando el diccionario de flutter"
import 'package:flutter/material.dart';
//main:arrancar Indica la acción inicial de la app
//=> "lo qué" Para una sola cosa. En este caso, arranca runApp (la aplicacion) de nombre MyApp
//extends se usa para ampliar lo que hay dentro. MyApp: un Widget. extends lo que hay dentro de ese Widget
void main() => runApp(MyApp());
//build construir, para crear lo que hay dentro de MyApp. Aquí está el esquema general de la app: tema, color principal (el de appbar) y páginas que conntiene. En este caso, solo "Home"
class MyApp extends StatelessWidget {
@override
@jesusrp98
jesusrp98 / app_model.dart
Created April 17, 2019 10:36
Scoped model which inits the notification system
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
// ...
class AppModel extends Model {
static final FlutterLocalNotificationsPlugin _notifications =
FlutterLocalNotificationsPlugin();
// ...
FlutterLocalNotificationsPlugin get notifications => _notifications;
@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(
@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 / 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 / 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 / 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 / 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 / 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 / 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>[
// ...