Skip to content

Instantly share code, notes, and snippets.

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
// Offset from offscreen below to stopping below the top of the screen.
final Animatable<Offset> _kBottomUpTween = Tween<Offset>(
begin: const Offset(0.0, 1.0),
@andrewpmoore
andrewpmoore / deploy.dart
Created November 5, 2024 17:02
Script to use google console api to build a flutter app and deploy to the internal test track
import 'dart:convert';
import 'dart:io';
import 'package:googleapis/androidpublisher/v3.dart';
import 'package:googleapis_auth/auth_io.dart';
const _flutterPath = 'C:/flutter/bin/flutter.bat';
const _workingDirectory = 'c:/users/x/projects/project_root_dir';
const _credentialsFile = 'c:/your_service_account_path/profile-e045e9cef64e.json';
const _packageName = 'com.zzz.xxx.yyy';
const _whatsNew = 'This is a test of the upload script.';
@joethephish
joethephish / text-field-with-colour.swift
Last active November 16, 2024 19:17
Sample code for how to highlight text within a TextField in SwiftUI in my app
TextField(placeholder, text:$event.title, axis: Axis.vertical)
.keyboardType(.default)
.focused($textFieldFocus, equals:controlId)
// When newline is detected, create a new item (or delete if it's empty)
// We'd do this in onKeyPress(.return) but that's only for hardware keyboards
.lineLimit(100, reservesSpace: false)
.overlay(alignment: Alignment(horizontal:.leading, vertical: .center)) {
GeometryReader { proxy in
@MaherSafadii
MaherSafadii / gist:0393dd9593175e76816569b13028f1f8
Created October 31, 2024 10:46
SwiftUI Demo Config - Flutter replica
import 'package:cupertino_calendar_picker/cupertino_calendar_picker.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const CupertinoApp(
localizationsDelegates: [
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultMaterialLocalizations.delegate,
@juliensagot
juliensagot / CustomButtonStyle.swift
Created October 10, 2024 17:37
SwiftUI custom ButtonStyle example
import SwiftUI
struct CapsuleButtonStyle: ButtonStyle {
enum Appearance {
case plain
case outlined
}
let appearance: Appearance
@juliensagot
juliensagot / ResponsiveButtonStyle.swift
Last active November 22, 2024 13:04
Custom ButtonStyle boilerplate that doesn't take ages to update its `isPressed` state when using spring animations
struct ResponsiveButtonStyle: PrimitiveButtonStyle {
// Use this instead of `Configuration.isPressed`.
@State private var isPressed = false
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(isPressed ? 0.9 : 1)
.animation(.spring, value: isPressed)
._onButtonGesture { isPressed in
self.isPressed = isPressed
@juliensagot
juliensagot / VariableBlurView.swift
Last active April 15, 2025 21:17
SwiftUI variable blur view
import Foundation
import SwiftUI
import UIKit
extension UIBlurEffect {
public static func variableBlurEffect(radius: Double, imageMask: UIImage) -> UIBlurEffect? {
let methodType = (@convention(c) (AnyClass, Selector, Double, UIImage) -> UIBlurEffect).self
let selectorName = ["imageMask:", "effectWithVariableBlurRadius:"].reversed().joined()
let selector = NSSelectorFromString(selectorName)
@juliensagot
juliensagot / ValuePicker.swift
Last active April 12, 2025 23:57
Custom SwiftUI Picker
import SwiftUI
public struct ValuePicker<SelectionValue: Hashable, Content: View>: View {
private let title: LocalizedStringKey
private let selection: Binding<SelectionValue>
private let content: Content
public init(
_ title: LocalizedStringKey,
selection: Binding<SelectionValue>,
import Foundation
import SwiftUI
// MARK: - Custom Button Style
struct MobileMeButtonStyle: ButtonStyle {
// MARK: Metrics
@ScaledMetric private var cornerRadius = 12
@ScaledMetric private var horizontalLabelPadding = 12
@ScaledMetric private var verticalLabelPadding = 8
@tkashkin
tkashkin / PullToRefreshView.swift
Last active March 26, 2023 14:43
SwiftUI Pull to refresh view
import SwiftUI
struct PullToRefreshView: View
{
private static let minRefreshTimeInterval = TimeInterval(0.2)
private static let triggerHeight = CGFloat(100)
private static let indicatorHeight = CGFloat(100)
private static let fullHeight = triggerHeight + indicatorHeight
let backgroundColor: Color