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 'dart:convert';
void main() {
String dataString = """[
{
"placeImage":"images/fish2.jpg",
"placeName":"Ikan 2",
"placeItem":["fish, crab, seafood"],
"minOrder":20
}
@fabiancrx
fabiancrx / pageview_adaptive.dart
Created May 21, 2021 15:40
Flutter PageView with different page size
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@fabiancrx
fabiancrx / keyboard_dismiss.dart
Created August 23, 2021 15:38
Dissmiss the keyboard in Flutter when tapped or scrolled
/// Removes the current focus and hides the keyboard when
/// the user drags or taps this widget.
///
/// Place this widget somewhere near the top of your widget
/// tree and when the user drags or taps outside of a focused widget,
/// the focus will be removed and the keyboard will be hidden.
class KeyboardDismiss extends StatelessWidget {
final Widget child;
final bool dismissOnTap;
@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.
///
@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 / 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.
///
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);
/// 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;
@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
@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,