Skip to content

Instantly share code, notes, and snippets.

View BarryDaBee's full-sized avatar
💻

Olusesi Boluwatife Barry BarryDaBee

💻
View GitHub Profile
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
final List<Product> products = [
Product(name: 'Potato', quantity: '100', value: 1000),
Product(name: 'Pie', quantity: '100', value: 1500),
];
@BarryDaBee
BarryDaBee / selectable_button_method_1.dart
Created June 2, 2022 20:16
Simple selectable button demo
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
/// Determine the current position of the device.
///
/// When the location services are not enabled or permissions
/// are denied the `Future` will return an error.
Future<Position> _determinePosition() async {
bool serviceEnabled;
LocationPermission permission;
// Test if location services are enabled.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
import 'package:flutter/material.dart';
class CustomThumbShape extends SliderComponentShape {
final double thumbRadius;
const CustomThumbShape({
required this.thumbRadius,
});
@BarryDaBee
BarryDaBee / read_more.dart
Last active October 8, 2022 15:32
Implementation of common "Read more" feature to truncate and expand lengthy text on demand
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class ReadMore extends StatefulWidget {
final String text;
final TextStyle? textStyle;
final String readMoreText;
final TextStyle? readMoreTextStyle;
final int maxLines;
final int steps;
@BarryDaBee
BarryDaBee / custom_track_shape.dart
Created November 13, 2022 06:04
Custom track shape for flutter slider widget without height
import 'package:flutter/material.dart';
class CustomTrackShape extends RoundedRectSliderTrackShape {
@override
Rect getPreferredRect(
{required RenderBox parentBox,
Offset offset = Offset.zero,
required SliderThemeData sliderTheme,
bool isEnabled = false,
bool isDiscrete = false}) {
@BarryDaBee
BarryDaBee / resizing_card.dart
Created November 22, 2022 06:35
Demonstration of how to get the size of a widget and delay its rendering by one frame
class ResizingCard extends StatefulWidget {
const ResizingCard({Key? key, this.onClose}) : super(key: key);
final VoidCallback? onClose;
@override
State<ResizingCard> createState() => _ResizingCardState();
}
class _ResizingCardState extends State<ResizingCard>
@BarryDaBee
BarryDaBee / read_more_with_mention.dart
Last active December 29, 2022 08:50
Read More text with support for @mention. To be extended to accept a map of indicators and corresponding textStyles
class ReadMoreWithMention extends StatefulWidget {
final String text;
final TextStyle? textStyle;
final String readMoreText;
final TextStyle? readMoreTextStyle;
final int maxLines;
final int steps;
// final bool shouldUseSteps;
const ReadMoreWithMention({
Key? key,
@BarryDaBee
BarryDaBee / password_validator.dart
Last active March 2, 2023 13:04
A simple widget for validating password conditions like length >= 8, hasNumber etc
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
@BarryDaBee
BarryDaBee / card_input_formatter.dart
Created March 6, 2023 08:54
A simple text input formatter for grouping text by splitAt and separating with the separator e.g. 2222-1111 has splitAt: 4 and seperator: '-'
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class CardInputFormatter extends TextInputFormatter {
CardInputFormatter({required this.separator, this.splitAt = 4});
final String separator;
final int splitAt;
@override
TextEditingValue formatEditUpdate(