Skip to content

Instantly share code, notes, and snippets.

View s859's full-sized avatar

Steve Zwart s859

  • Lexington, KY
View GitHub Profile
@s859
s859 / date_field.dart
Created July 24, 2019 19:13
Formatting for US Date mm/dd/yyyy
TextEditingController _birthdayTextController = TextEditingController();
final UsDateTextInputFormatter _dateTextInputFormatter =
UsDateTextInputFormatter();
String _validateDate(String value) {
final RegExp dateExp =
RegExp(r'^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$');
if (!dateExp.hasMatch(value)) return 'mmddyyyy';
return null;
@s859
s859 / zipcode_field.dart
Created July 24, 2019 19:07
Formatting for US Zip Code
TextEditingController _zipTextController = TextEditingController();
final ZipTextInputFormatter _zipTextInputFormatter = ZipTextInputFormatter();
String _validateZip(String value) {
if (value.isEmpty) return 'Enter zipcode';
if (value.length < 5) return '5 or more chars';
if (value.length == 5) {
final RegExp zip1Exp = RegExp(r'\d\d\d\d\d$');
if (zip1Exp.hasMatch(value)) {
@s859
s859 / state_field.dart
Created July 24, 2019 18:57
Formatting for US State abbreviations
TextEditingController _stateTextController = TextEditingController();
String _validateState(String value) {
if (value.isEmpty) return 'Enter state';
if (value.length != 2) return '2 character state';
RegExp stateExp =
RegExp(r"A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|"
r"M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|"
r"V[AIT]|W[AIVY]");
if (!stateExp.hasMatch(value)) return 'Invalid';
@s859
s859 / soc_security_field.dart
Last active July 24, 2019 18:50
Formatting for US Social Security number field
TextEditingController _ssnTextController = TextEditingController();
final SocSecTextInputFormatter _socSecNumberFormatter =
SocSecTextInputFormatter();
String _validateSocSec(String value) {
final RegExp socSecExp = RegExp(r'\d\d\d\-\d\d\-\d\d\d\d$');
if (!socSecExp.hasMatch(value)) return '9 digit SSN';
return null;
}
@s859
s859 / phone_field.dart
Last active July 24, 2019 18:44
Formatting for US phone number field
TextEditingController _PhoneNumberTextController = TextEditingController();
final UsPhoneTextInputFormatter _phoneNumberFormatter =
UsPhoneTextInputFormatter();
String _validatePhoneNumber(String value) {
final RegExp phoneExp = RegExp(r'^\(\d\d\d\) \d\d\d\-\d\d\d\d$');
if (!phoneExp.hasMatch(value)) return '10 digit phone #';
return null;
}
@s859
s859 / applicant.dart
Created July 24, 2019 18:27
Defines Applicant in the rental_app form
import 'dart:io' as io;
import 'dart:convert';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_mailer/flutter_mailer.dart';
class Applicant {
String applicantJson;
String pathName;
io.Directory directory;
io.File applicantFile;
@s859
s859 / input_decoration.dart
Created July 24, 2019 17:49
Provides a suitable InputDecoration for TextFormFields
import 'package:flutter/material.dart';
const kTextFieldDecoration = InputDecoration(
hintText: 'Enter a value',
filled: true,
contentPadding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
enabledBorder: OutlineInputBorder(
@s859
s859 / number_formatter.dart
Created July 24, 2019 12:23
The following set of TextInputFormatters provides as-you-type formatting for United States dates, States, Zip Codes and Social Security numbers
import 'package:flutter/services.dart';
/// Format a phone number in format (###) ###-####
class UsPhoneTextInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
final int newTextLength = newValue.text.length;
@s859
s859 / image_picker.dart
Last active July 23, 2019 19:29
Image picker with height and width optimized for ID cards
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override