Skip to content

Instantly share code, notes, and snippets.

View folaoluwafemi's full-sized avatar

Fola Oluwafemi folaoluwafemi

View GitHub Profile
@folaoluwafemi
folaoluwafemi / compare_queries.dart
Last active July 8, 2023 22:40
A method for comparing queries in dart
abstract final class UtilFunctions {
static bool compareQueries(String value, String query) {
final String formattedValue = value.trim().toLowerCase();
final List<String> queryWords = query.split(' ');
if (queryWords.length == 1) {
return formattedValue.contains(query.trim().toLowerCase());
}
bool hasMatch = false;
for (String queryWord in queryWords) {
hasMatch = formattedValue.contains(queryWord.trim().toLowerCase());
@folaoluwafemi
folaoluwafemi / custom_animation_builder.dart
Last active June 27, 2023 17:05
A simple but useful widget to implement animation, it provides a builder that exposes the current animation value, and calls the build method at every tick.
import 'package:flutter/widgets.dart';
typedef CustomAnimationBuilderCallback = Widget Function(
BuildContext context,
double value,
Widget? child,
);
class CustomAnimationBuilder extends StatefulWidget {
final Duration duration;
@folaoluwafemi
folaoluwafemi / timer_mixin.dart
Last active May 16, 2023 16:32
A mixin for adding timer to state or screens e.g when there's a reset password otp timer
import 'dart:async';
/// A mixin for adding timer to state or screens
///e.g when there's a reset password otp timer
///
/// Add it to your immutable state class like so:
/// class PasswordState extends AuthState with TimerMixin {
/// ...
///
/// @override
@folaoluwafemi
folaoluwafemi / main.dart
Created May 10, 2023 14:31
avian-epoch-8139
void main() {
print('compute line height ${computeTextSizeFromText('''
font-family: Poppins;
font-size: 25px;
font-weight: 500;
line-height: 38px;
letter-spacing: 0em;
text-align: left;
''')}',);
@folaoluwafemi
folaoluwafemi / main.dart
Created May 10, 2023 14:31
avian-epoch-8139
void main() {
print('compute line height ${computeTextSizeFromText('''
font-family: Poppins;
font-size: 25px;
font-weight: 500;
line-height: 38px;
letter-spacing: 0em;
text-align: left;
''')}',);
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class AllowPointer extends SingleChildRenderObjectWidget {
const AllowPointer({
super.key,
this.allowing = true,
this.ignoringSemantics,
super.child,
});
@folaoluwafemi
folaoluwafemi / multi_point_scroll_view.dart
Created May 5, 2023 15:21
A SingleChildScrollView that allows control over the number of pointers that trigger scrolling
// ignore_for_file: lines_longer_than_80_chars
import 'dart:async';
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart' hide ScrollableState;
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
@folaoluwafemi
folaoluwafemi / n_pointer_single_child_scroll_view.dart
Created May 4, 2023 13:23
A single child scroll view widget that allows control over the number of pointers that enable scrolling
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
///copied and modified from [stackoverflow](https://stackoverflow.com/questions/76155321/how-can-i-recognize-two-fingers-on-the-screen-in-flutter/76156071?noredirect=1#comment134304616_76156071)
class NPointerSingleChildScrollView extends StatefulWidget {
final int numberOfPointers;
final Axis scrollDirection;
final bool reverse;
final EdgeInsetsGeometry? padding;
@folaoluwafemi
folaoluwafemi / main.dart
Created March 25, 2023 02:12
snowy-glacier-9997
void main() {
listPatternExample();
mapPatternExample();
recordPatternExample();
print(switchExpressionExample());
print(complexSwitchExpressionExample());
variablePatternExample();
nullPatternExample();
castPatternExample();
patternInConditions();
@folaoluwafemi
folaoluwafemi / interpolate_colors.dart
Created March 9, 2023 21:29
A simple function to interpolate between a list of colors
Color interpolateColors(double value, List<Color> colors) {
assert(value >= 0 || value <= 1, 'value must be between 0 and 1');
final int colorListLength = colors.length - 1;
final int maxExpectedIndex = (colorListLength * value).ceil();
final int minExpectedIndex = (colorListLength * value).floor();
final Color minColor = colors[minExpectedIndex];
final Color maxColor = colors[maxExpectedIndex];