Skip to content

Instantly share code, notes, and snippets.

View ChrisMarxDev's full-sized avatar

Chris ChrisMarxDev

View GitHub Profile
@ChrisMarxDev
ChrisMarxDev / line_text_painter.dart
Created July 22, 2024 07:15
Paint a white rectangle exactly behind the text
class LineWidgetText extends ConsumerStatefulWidget {
const LineWidgetText({
required this.element,
super.key,
});
final LineElement element;
@override
ConsumerState<LineWidgetText> createState() => _LineWidgetTextState();
@ChrisMarxDev
ChrisMarxDev / device_kind_pan_gesture_detector.dart
Last active July 19, 2024 17:51
Pan Gesture Recogniser that differentiates between device types
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
// pan gesture detector that only responds to specific device kinds
// e.g. only responds to mouse drags but ignores trackpad drags
class DeviceKindPanGestureDetector extends StatefulWidget {
const DeviceKindPanGestureDetector({
required this.child,
required this.onStart,
required this.onUpdate,
@ChrisMarxDev
ChrisMarxDev / Code.gs
Created March 6, 2024 09:09
Apps script gmail to crm integration
function loadAddOn(event) {
var accessToken = event.gmail.accessToken;
var messageId = event.gmail.messageId;
GmailApp.setCurrentMessageAccessToken(accessToken);
var mailMessage = GmailApp.getMessageById(messageId);
var from = mailMessage.getFrom()
var mail = from.split("<")[1].split(">")[0];
var name = from.split("<")[0];
var sendDataButton = CardService.newTextButton()
@ChrisMarxDev
ChrisMarxDev / interactable_card.dart
Created July 22, 2023 08:41
Bouncy Card Widget
import 'package:flutter/material.dart';
// I will have to clean this a little bit, I pasted my context_extension below so it works out of the box
class InteractableCard extends StatefulWidget {
const InteractableCard({
required this.child,
this.highlightColor,
super.key,
this.onTap,
this.unselectedColor,
@ChrisMarxDev
ChrisMarxDev / analytics.dart
Created June 8, 2022 13:01
Firebase analytics
import 'dart:async';
import 'dart:convert';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'logging.dart';
void logEvent(
String name, [
Map<String, Object>? params,
@ChrisMarxDev
ChrisMarxDev / pre-push
Last active July 22, 2021 08:21
Flutter pre-push git hook. Does not push if analyse or test fail.
#!/bin/sh
# To use add to your projects `.git/hooks/`
# Should be named `pre-push`
# Don't forget to make it executable with `chmod +x`
# run Flutter analyze + test
flutter analyze
if [ $? -ne 0 ]; then
exit 1
@ChrisMarxDev
ChrisMarxDev / meta_coin.dart
Last active June 17, 2020 13:56
Smart contract related functions to call MetaCoin example
Future<String> sendCoind(String targetAddressHex, int amount) async {
EthereumAddress address = EthereumAddress.fromHex(targetAddressHex);
// uint in smart contract means BigInt for us
var bigAmount = BigInt.from(amount);
// sendCoin transaction
var response = await submit("sendCoin", [address, bigAmount]);
// hash of the transaction
return response;
}
@ChrisMarxDev
ChrisMarxDev / query_submit.dart
Last active June 17, 2020 13:54
Query data & submit a transaction with web3dart
Future<String> submit(String functionName, List<dynamic> args) async {
EthPrivateKey credentials = EthPrivateKey.fromHex(
"3d272d3193203d7a4458ea2a38ace936075c776512fc27093597ca2c790602a9");
DeployedContract contract = await loadContract();
final ethFunction = contract.function(functionName);
var result = await ethClient.sendTransaction(
credentials,
@ChrisMarxDev
ChrisMarxDev / load_contract.dart
Last active June 19, 2020 08:20
Function to load up a web3dart contract
// you will need the following import
// import 'package:flutter/services.dart';
Future<DeployedContract> loadContract() async {
String abiCode = await rootBundle.loadString("assets/abi.json");
String contractAddress = "0x8A30f78133176ed5E6CcB0AE8429AEEBf4c82Ffc";
final contract = DeployedContract(ContractAbi.fromJson(abiCode, "MetaCoin"),
EthereumAddress.fromHex(contractAddress));
@ChrisMarxDev
ChrisMarxDev / init_clients.dart
Last active June 19, 2020 08:19
Initialize a web3client for Flutter
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
class _MyHomePageState extends State<MyHomePage> {
Client httpClient;
Web3Client ethClient;
@override
void initState() {
super.initState();