Skip to content

Instantly share code, notes, and snippets.

View rapPayne's full-sized avatar
:octocat:
Working from home

Rap Payne rapPayne

:octocat:
Working from home
View GitHub Profile
@rapPayne
rapPayne / main.dart
Created March 10, 2024 21:37
Flutter responsive scrolling
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@rapPayne
rapPayne / main.dart
Created December 23, 2023 00:54
obsidian-echo-0681
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@rapPayne
rapPayne / inherit_me.dart
Created November 22, 2023 23:24 — forked from slightfoot/inherit_me.dart
Inherited Widget Example - by Simon Lightfoot - Humpday Q&A :: 22nd November 2023 #Flutter #Dart
// MIT License
//
// Copyright (c) 2023 Simon Lightfoot
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@rapPayne
rapPayne / main.dart
Last active November 22, 2023 18:32
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
void main() {
runApp(const RootWidget());
}
class RootWidget extends StatefulWidget {
const RootWidget({super.key});
@rapPayne
rapPayne / ChangeName_plain.jsx
Last active September 14, 2023 17:43
Unstyled React component
// Super-simple component -- An input with a label and a button. No big deal.
export const ChangeName = ({ user, update, save }) => {
return (
<section>
<div>
<label htmlFor="user">User name</label>
<input id="user" onChange={e => update(e.target.value)} value={user} />
</div>
<button onClick={save}>Save</button>
</section>
@rapPayne
rapPayne / ChangeName.css
Last active September 14, 2023 17:55
React component styled with CSS nesting
/*
** Note the use of CSS nesting. Nesting all styles underneath a class of
** ChangeName ensures they will ONLY be seen in the ChangeName component.
** 🙌 This is the best of both worlds!
*/
.ChangeName {
border: 1px solid var(--dark1);
padding: 10px;
&>div {
@rapPayne
rapPayne / ChangeName_styled.jsx
Last active September 14, 2023 17:51
React component styled with inline styles
// 💩
// Much more complex; see all the "style={styles.whatever}"? They get in the way
// of quickly understanding what's in this component.
export const ChangeName = ({ user, update, save }) => {
return (
<section style={styles.wrapper}>
<div style={styles.formGroup}>
<label htmlFor="user" style={styles.label}>User name</label>
<input id="user" onChange={e => update(e.target.value)} value={user} />
@rapPayne
rapPayne / Register.dart
Created October 22, 2020 02:01
Adding focus
String _validateEmail(String email) {
// 1
RegExp regex = RegExp(r'\w+@\w+\.\w+');
// Add the following line to set focus to the email field
if (email.isEmpty || !regex.hasMatch(email)) _emailFocusNode.requestFocus();
// 2
if (email.isEmpty)
return 'We need an email address';
else if (!regex.hasMatch(email))
// 3
@rapPayne
rapPayne / Register.dart
Created October 21, 2020 22:42
Validating a checkbox -- after
Widget get _buildAgreeToTermsField {
// TODO 8: Wrap the Column with a FormField<bool>
return FormField<bool>(
// 1
initialValue: _agree,
// 2
builder: (FormFieldState<bool> state) {
return Column(
children: <Widget>[
Row(
@rapPayne
rapPayne / Register.dart
Last active October 21, 2020 22:33
Validating a checkbox -- before
Widget get _buildAgreeToTermsField {
// TODO 8: Wrap the Column with a FormField<bool>
return Column(
children: <Widget>[
Row(
children: <Widget>[
Checkbox(
value: _agree,
onChanged: (bool val) => setState(() {
_agree = val;