Skip to content

Instantly share code, notes, and snippets.

@agusibrahim
Created July 15, 2022 14:53
Show Gist options
  • Save agusibrahim/528697467037f5d81171fec09bb444f9 to your computer and use it in GitHub Desktop.
Save agusibrahim/528697467037f5d81171fec09bb444f9 to your computer and use it in GitHub Desktop.
missing file for flutterflow
import 'package:flutter/material.dart';
class FlutterFlowIconButton extends StatelessWidget {
const FlutterFlowIconButton(
{Key? key,
this.borderColor,
this.borderRadius,
this.borderWidth,
this.buttonSize,
this.fillColor,
required this.icon,
this.onPressed})
: super(key: key);
final double? borderRadius;
final double? buttonSize;
final Color? fillColor;
final Color? borderColor;
final double? borderWidth;
final Widget icon;
final void Function()? onPressed;
@override
Widget build(BuildContext context) => Material(
borderRadius:
borderRadius != null ? BorderRadius.circular(borderRadius!) : null,
color: Colors.transparent,
clipBehavior: Clip.antiAlias,
child: Ink(
width: buttonSize,
height: buttonSize,
decoration: BoxDecoration(
color: fillColor,
border: Border.all(
color: borderColor ?? Colors.transparent,
width: borderWidth ?? 0,
),
borderRadius: borderRadius != null
? BorderRadius.circular(borderRadius!)
: null,
),
child: IconButton(
icon: icon,
onPressed: onPressed,
splashRadius: buttonSize,
),
),
);
}
// ignore_for_file: overridden_fields, annotate_overrides
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';
const kThemeModeKey = '__theme_mode__';
SharedPreferences? _prefs;
abstract class FlutterFlowTheme {
static Future initialize() async =>
_prefs = await SharedPreferences.getInstance();
static ThemeMode get themeMode {
final darkMode = _prefs?.getBool(kThemeModeKey);
return darkMode == null
? ThemeMode.system
: darkMode
? ThemeMode.dark
: ThemeMode.light;
}
static void saveThemeMode(ThemeMode mode) => mode == ThemeMode.system
? _prefs?.remove(kThemeModeKey)
: _prefs?.setBool(kThemeModeKey, mode == ThemeMode.dark);
static FlutterFlowTheme of(BuildContext context) =>
Theme.of(context).brightness == Brightness.dark
? DarkModeTheme()
: LightModeTheme();
late Color primaryColor;
late Color secondaryColor;
late Color tertiaryColor;
late Color alternate;
late Color primaryBackground;
late Color secondaryBackground;
late Color primaryText;
late Color secondaryText;
late Color primaryBtnText;
late Color lineColor;
String get title1Family => typography.title1Family;
TextStyle get title1 => typography.title1;
String get title2Family => typography.title2Family;
TextStyle get title2 => typography.title2;
String get title3Family => typography.title3Family;
TextStyle get title3 => typography.title3;
String get subtitle1Family => typography.subtitle1Family;
TextStyle get subtitle1 => typography.subtitle1;
String get subtitle2Family => typography.subtitle2Family;
TextStyle get subtitle2 => typography.subtitle2;
String get bodyText1Family => typography.bodyText1Family;
TextStyle get bodyText1 => typography.bodyText1;
String get bodyText2Family => typography.bodyText2Family;
TextStyle get bodyText2 => typography.bodyText2;
Typography get typography => ThemeTypography(this);
}
class LightModeTheme extends FlutterFlowTheme {
late Color primaryColor = const Color(0xFF4B39EF);
late Color secondaryColor = const Color(0xFF39D2C0);
late Color tertiaryColor = const Color(0xFFEE8B60);
late Color alternate = const Color(0xFFFF5963);
late Color primaryBackground = const Color(0xFFF1F4F8);
late Color secondaryBackground = const Color(0xFFFFFFFF);
late Color primaryText = const Color(0xFF101213);
late Color secondaryText = const Color(0xFF57636C);
late Color primaryBtnText = Color(0xFFFFFFFF);
late Color lineColor = Color(0xFFE0E3E7);
}
abstract class Typography {
String get title1Family;
TextStyle get title1;
String get title2Family;
TextStyle get title2;
String get title3Family;
TextStyle get title3;
String get subtitle1Family;
TextStyle get subtitle1;
String get subtitle2Family;
TextStyle get subtitle2;
String get bodyText1Family;
TextStyle get bodyText1;
String get bodyText2Family;
TextStyle get bodyText2;
}
class ThemeTypography extends Typography {
ThemeTypography(this.theme);
final FlutterFlowTheme theme;
String get title1Family => 'Roboto';
TextStyle get title1 => GoogleFonts.getFont(
'Roboto',
color: theme.primaryText,
fontWeight: FontWeight.normal,
fontSize: 24,
);
String get title2Family => 'Roboto';
TextStyle get title2 => GoogleFonts.getFont(
'Roboto',
color: theme.secondaryText,
fontWeight: FontWeight.normal,
fontSize: 22,
);
String get title3Family => 'Roboto';
TextStyle get title3 => GoogleFonts.getFont(
'Roboto',
color: theme.primaryText,
fontWeight: FontWeight.normal,
fontSize: 20,
);
String get subtitle1Family => 'Roboto';
TextStyle get subtitle1 => GoogleFonts.getFont(
'Roboto',
color: theme.primaryText,
fontWeight: FontWeight.normal,
fontSize: 18,
);
String get subtitle2Family => 'Roboto';
TextStyle get subtitle2 => GoogleFonts.getFont(
'Roboto',
color: theme.secondaryText,
fontWeight: FontWeight.normal,
fontSize: 16,
);
String get bodyText1Family => 'Roboto';
TextStyle get bodyText1 => GoogleFonts.getFont(
'Roboto',
color: theme.primaryText,
fontWeight: FontWeight.normal,
fontSize: 14,
);
String get bodyText2Family => 'Roboto';
TextStyle get bodyText2 => GoogleFonts.getFont(
'Roboto',
color: theme.secondaryText,
fontWeight: FontWeight.normal,
fontSize: 14,
);
}
class DarkModeTheme extends FlutterFlowTheme {
late Color primaryColor = const Color(0xFF4B39EF);
late Color secondaryColor = const Color(0xFF39D2C0);
late Color tertiaryColor = const Color(0xFFEE8B60);
late Color alternate = const Color(0xFFFF5963);
late Color primaryBackground = const Color(0xFF1A1F24);
late Color secondaryBackground = const Color(0xFF101213);
late Color primaryText = const Color(0xFFFFFFFF);
late Color secondaryText = const Color(0xFF95A1AC);
late Color primaryBtnText = Color(0xFFFFFFFF);
late Color lineColor = Color(0xFF22282F);
}
extension TextStyleHelper on TextStyle {
TextStyle override({
String? fontFamily,
Color? color,
double? fontSize,
FontWeight? fontWeight,
double? letterSpacing,
FontStyle? fontStyle,
bool useGoogleFonts = true,
TextDecoration? decoration,
double? lineHeight,
}) =>
useGoogleFonts
? GoogleFonts.getFont(
fontFamily!,
color: color ?? this.color,
fontSize: fontSize ?? this.fontSize,
letterSpacing: letterSpacing ?? this.letterSpacing,
fontWeight: fontWeight ?? this.fontWeight,
fontStyle: fontStyle ?? this.fontStyle,
decoration: decoration,
height: lineHeight,
)
: copyWith(
fontFamily: fontFamily,
color: color,
fontSize: fontSize,
letterSpacing: letterSpacing,
fontWeight: fontWeight,
fontStyle: fontStyle,
decoration: decoration,
height: lineHeight,
);
}
import 'dart:io';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart';
export 'lat_lng.dart';
export 'place.dart';
export 'dart:math' show min, max;
export 'dart:convert' show jsonEncode, jsonDecode;
export 'package:intl/intl.dart';
export 'package:page_transition/page_transition.dart';
T valueOrDefault<T>(T? value, T defaultValue) =>
(value is String && value.isEmpty) || value == null ? defaultValue : value;
String dateTimeFormat(String format, DateTime? dateTime) {
if (dateTime == null) {
return '';
}
if (format == 'relative') {
return timeago.format(dateTime);
}
return DateFormat(format).format(dateTime);
}
Future launchURL(String url) async {
var uri = Uri.parse(url).toString();
try {
await launch(uri);
} catch (e) {
throw 'Could not launch $uri: $e';
}
}
enum FormatType {
decimal,
percent,
scientific,
compact,
compactLong,
custom,
}
enum DecimalType {
automatic,
periodDecimal,
commaDecimal,
}
String formatNumber(
num? value, {
required FormatType formatType,
DecimalType? decimalType,
String? currency,
bool toLowerCase = false,
String? format,
String? locale,
}) {
var formattedValue = '';
switch (formatType) {
case FormatType.decimal:
switch (decimalType!) {
case DecimalType.automatic:
formattedValue = NumberFormat.decimalPattern().format(value);
break;
case DecimalType.periodDecimal:
formattedValue = NumberFormat.decimalPattern('en_US').format(value);
break;
case DecimalType.commaDecimal:
formattedValue = NumberFormat.decimalPattern('es_PA').format(value);
break;
}
break;
case FormatType.percent:
formattedValue = NumberFormat.percentPattern().format(value);
break;
case FormatType.scientific:
formattedValue = NumberFormat.scientificPattern().format(value);
if (toLowerCase) {
formattedValue = formattedValue.toLowerCase();
}
break;
case FormatType.compact:
formattedValue = NumberFormat.compact().format(value);
break;
case FormatType.compactLong:
formattedValue = NumberFormat.compactLong().format(value);
break;
case FormatType.custom:
final hasLocale = locale != null && locale.isNotEmpty;
formattedValue = NumberFormat(format, hasLocale ? locale : null).format(value);
}
if (formattedValue.isEmpty) {
return value.toString();
}
if (currency != null) {
final currencySymbol = currency.isNotEmpty ? currency : NumberFormat.simpleCurrency().format(0.0).substring(0, 1);
formattedValue = '$currencySymbol$formattedValue';
}
return formattedValue;
}
DateTime get getCurrentTimestamp => DateTime.now();
extension DateTimeComparisonOperators on DateTime {
bool operator <(DateTime other) => isBefore(other);
bool operator >(DateTime other) => isAfter(other);
bool operator <=(DateTime other) => this < other || isAtSameMomentAs(other);
bool operator >=(DateTime other) => this > other || isAtSameMomentAs(other);
}
bool get isAndroid => !kIsWeb && Platform.isAndroid;
bool get isiOS => !kIsWeb && Platform.isIOS;
bool get isWeb => kIsWeb;
bool responsiveVisibility({
required BuildContext context,
bool phone = true,
bool tablet = true,
bool tabletLandscape = true,
bool desktop = true,
}) {
final width = MediaQuery.of(context).size.width;
if (width < 479) {
return phone;
} else if (width < 767) {
return tablet;
} else if (width < 991) {
return tabletLandscape;
} else {
return desktop;
}
}
const kTextValidatorUsernameRegex = r'^[a-zA-Z][a-zA-Z0-9_-]{2,16}$';
const kTextValidatorEmailRegex =
r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?)*$";
const kTextValidatorWebsiteRegex =
r'(https?:\/\/)?(www\.)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)|(https?:\/\/)?(www\.)?(?!ww)[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)';
void showSnackbar(
BuildContext context,
String message, {
bool loading = false,
int duration = 4,
}) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
if (loading)
Padding(
padding: EdgeInsetsDirectional.only(end: 10.0),
child: Container(
height: 20,
width: 20,
child: const CircularProgressIndicator(
color: Colors.white,
),
),
),
Text(message),
],
),
duration: Duration(seconds: duration),
),
);
}
extension FFStringExt on String {
String maybeHandleOverflow({int? maxChars, String replacement = ''}) =>
maxChars != null && length > maxChars ? replaceRange(maxChars, null, replacement) : this;
}
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:flutter/material.dart';
import 'package:auto_size_text/auto_size_text.dart';
class FFButtonOptions {
const FFButtonOptions({
this.textStyle,
this.elevation,
this.height,
this.width,
this.padding,
this.color,
this.disabledColor,
this.disabledTextColor,
this.splashColor,
this.iconSize,
this.iconColor,
this.iconPadding,
this.borderRadius,
this.borderSide,
});
final TextStyle? textStyle;
final double? elevation;
final double? height;
final double? width;
final EdgeInsetsGeometry? padding;
final Color? color;
final Color? disabledColor;
final Color? disabledTextColor;
final Color? splashColor;
final double? iconSize;
final Color? iconColor;
final EdgeInsetsGeometry? iconPadding;
final BorderRadius? borderRadius;
final BorderSide? borderSide;
}
class FFButtonWidget extends StatefulWidget {
const FFButtonWidget({
Key? key,
required this.text,
required this.onPressed,
this.icon,
this.iconData,
required this.options,
this.showLoadingIndicator = true,
}) : super(key: key);
final String text;
final Widget? icon;
final IconData? iconData;
final Function() onPressed;
final FFButtonOptions options;
final bool showLoadingIndicator;
@override
State<FFButtonWidget> createState() => _FFButtonWidgetState();
}
class _FFButtonWidgetState extends State<FFButtonWidget> {
bool loading = false;
@override
Widget build(BuildContext context) {
Widget textWidget = loading
? Center(
child: Container(
width: 23,
height: 23,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
widget.options.textStyle!.color ?? Colors.white,
),
),
),
)
: AutoSizeText(
widget.text,
style: widget.options.textStyle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
final onPressed = widget.showLoadingIndicator
? () async {
if (loading) {
return;
}
setState(() => loading = true);
try {
await widget.onPressed();
} finally {
if (mounted) {
setState(() => loading = false);
}
}
}
: () => widget.onPressed();
ButtonStyle style = ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(
borderRadius:
widget.options.borderRadius ?? BorderRadius.circular(8.0),
side: widget.options.borderSide ?? BorderSide.none,
),
),
foregroundColor: MaterialStateProperty.resolveWith<Color?>(
(states) {
if (states.contains(MaterialState.disabled)) {
return widget.options.disabledTextColor;
}
return widget.options.textStyle!.color;
},
),
backgroundColor: MaterialStateProperty.resolveWith<Color?>(
(states) {
if (states.contains(MaterialState.disabled)) {
return widget.options.disabledColor;
}
return widget.options.color;
},
),
overlayColor: MaterialStateProperty.resolveWith<Color?>((states) {
if (states.contains(MaterialState.pressed)) {
return widget.options.splashColor;
}
return null;
}),
padding: MaterialStateProperty.all(widget.options.padding ??
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0)),
elevation:
MaterialStateProperty.all<double>(widget.options.elevation ?? 2.0),
);
if (widget.icon != null || widget.iconData != null) {
return Container(
height: widget.options.height,
width: widget.options.width,
child: ElevatedButton.icon(
icon: Padding(
padding: widget.options.iconPadding ?? EdgeInsets.zero,
child: widget.icon ??
FaIcon(
widget.iconData,
size: widget.options.iconSize,
color: widget.options.iconColor ??
widget.options.textStyle!.color,
),
),
label: textWidget,
onPressed: onPressed,
style: style,
),
);
}
return Container(
height: widget.options.height,
width: widget.options.width,
child: ElevatedButton(
onPressed: onPressed,
style: style,
child: textWidget,
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment