Skip to content

Instantly share code, notes, and snippets.

View CoderNamedHendrick's full-sized avatar
🥷

Sebastine Odeh CoderNamedHendrick

🥷
View GitHub Profile
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class ImagePickerField extends StatefulWidget {
const ImagePickerField({Key? key}) : super(key: key);
@override
State<ImagePickerField> createState() => _ImagePickerFieldState();
}
@CoderNamedHendrick
CoderNamedHendrick / main.dart
Last active July 10, 2023 03:17
form validations
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@CoderNamedHendrick
CoderNamedHendrick / animated_splash.dart
Last active June 15, 2023 20:00
A splash screen with some animations going on.
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
@CoderNamedHendrick
CoderNamedHendrick / chat_message_render_box.dart
Created May 15, 2023 19:32 — forked from craiglabenz/chat_message_render_box.dart
Demonstrates a custom RenderObject that draws chat messages like WhatsApp, where the `sentAt` timestamp is tucked into the last line if it fits
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
/// A resuable widget for getting a page to refresh without needing to scroll with the ugly scroll behaviour
/// on ios. Used by wrapping the widget with the view with this widget as so
/// class MyHomePage extends StatelessWidget {
/// const MyHomePage({super.key, required this.title});
///
/// final String title;
///
/// @override
/// Widget build(BuildContext context) {
/// return NoScrollRefreshWidget(
@CoderNamedHendrick
CoderNamedHendrick / either.dart
Last active August 2, 2023 16:09
Implementing Options in dart
import 'dart:async';
typedef Lazy<T> = T Function();
/// Represents a value of one of two possible types.
/// Instances of [Either] are either an instance of [Left] or [Right].
///
/// [Left] is used for "failure".
/// [Right] is used for "success".
abstract class Either<L, R> {
@CoderNamedHendrick
CoderNamedHendrick / amount_formatter.dart
Created March 24, 2023 13:05
Amount input formatter with decimal entry
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
final RegExp _mantissaSeparatorRegexp = RegExp(r'[,.]');
final RegExp _illegalCharsRegexp = RegExp(r'[^\d-,.]+');
class AmountInputFormatter implements TextInputFormatter {
final int mantissaLength;
@CoderNamedHendrick
CoderNamedHendrick / firestore_exception_transformer.dart
Created March 11, 2023 14:06
A wrapper around firstore functions, great for abstracting firestore CRUD operations.
Future<Either<Exception, E>> firebaseTransform<E>(
Future<E> Function() callToStore) async {
try {
return Right(await callToStore.call());
} on Exception catch (e) {
if (e is FirebaseException && e.code == 'permission-denied') {
return const Left(
AuthException('You have no permission to this resource'));
}
if (e is FirebaseException) {
@CoderNamedHendrick
CoderNamedHendrick / main.dart
Created March 4, 2023 22:00
Some animations
class MyWidget extends StatefulWidget {
const MyWidget({super.key});
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget>
with SingleTickerProviderStateMixin {
late final AnimationController controller;