Skip to content

Instantly share code, notes, and snippets.

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

fabiancrx

🏠
Working from home
View GitHub Profile
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher.dart';
/// Flutter code sample for [BottomNavigationBar].
void main() => runApp(const BottomNavigationBarExampleApp());
class BottomNavigationBarExampleApp extends StatelessWidget {
const BottomNavigationBarExampleApp({super.key});
@fabiancrx
fabiancrx / late.dart
Created April 2, 2024 20:06
Eager vs late
void main() async{
final sample=Sample();
await Future.delayed(Duration(milliseconds:100));
for(int i=0;i<5;i++){
print(i);
sample.averageReading;
sample.averageReading2;
@fabiancrx
fabiancrx / main.dart
Created January 19, 2024 17:46
Stream POC
import 'dart:async';
import 'package:rxdart/rxdart.dart';
void main() async {
final fakeAdapter = FakeBluetoothAdapter();
final sub = fakeAdapter
.availableDevices()
.listen(print);
@fabiancrx
fabiancrx / dismissible_sample.dart
Created December 7, 2023 22:15
Sample of using dismissible with the top layer not clipping the dismissible background
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
@fabiancrx
fabiancrx / draggable_resizable sheet.dart
Last active January 29, 2024 11:52
Draggable resizable sheet
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: MyHomePage()));
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
/// Interacts with services and provide observables that read or update settings.
///
/// Controllers glue Data Services to Flutter Widgets. The SettingsController
/// uses the SettingsService to store and retrieve user settings.
class SettingsController with ChangeNotifier {
// Make SettingsService a private variable so it is not used directly. " Law of Demeter "
final SettingsService _settingsService;
late int counter;
import 'package:shared_preferences/shared_preferences.dart';
/// A service that stores and retrieves user settings.
///
/// This class persists its data via SharedPreferences plugin
class SettingsService {
final SharedPreferences _sharedPreferences;
SettingsService(this._sharedPreferences);
@fabiancrx
fabiancrx / periodic_caller.dart
Last active June 23, 2022 17:43
A widget that executes a callback periodically, respecting app lifecycle.
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
/// A widget that executes a [callback] on several conditions.
///
/// - If [pollingTime] is not null the [callback] will be executed periodically given that [pollingTime]
/// This widget respects the apps lifecycle and won't execute the callback if the app is in the background.
///
@fabiancrx
fabiancrx / global_loading_indicator.dart
Last active May 29, 2022 04:55
Example of a flutter app displaying a global loading Indicator
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final loadingProvider = StateProvider<bool>((ref) => false);
void main() => runApp(const ProviderScope(child: MaterialApp(home: GlobalLoadingIndicator(child: Home()))));
class Home extends ConsumerWidget {
const Home({Key? key}) : super(key: key);
@fabiancrx
fabiancrx / scroll_when_focus_gained.dart
Last active September 16, 2021 11:05
Automatically scroll to widget when focus gained in Flutter
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
/// Given a [focusNode] when it gains focus it will scroll to the widget that is wrapped by [ScrollWhenFocusGained]
/// Useful for when working with forms in which they keyboard can obscure areas of the screen.
/// It also provides a [onFocus] fallback method to be execute if the view could not be scrolled correctly.
///