Code Snippets Dart

Short texts Dart 🧑‍💻 Code snippets Dart ✍️ Reading lists Dart 👀

This helps validate the success data received from Persona against user registered data

void init() async { updateUserProfile = (await LocalStorage.getUserData()); loginModel = (await LocalStorage.getLoginData())!; inquiry = Inquiry( configuration: TemplateIdConfiguration( templateId: “${dotenv.env[‘PERSONA_TEMP_ID’]}”, environment: InquiryEnvironment.production, // kReleaseMode // ? InquiryEnvironment.production // : InquiryEnvironment.sandbox, iOSTheme: InquiryTheme( accentColor: Color(0xff22CB8E), primaryColor: Color(0xff22CB8E), buttonBackgroundColor: Color(0xff22CB8E), darkPrimaryColor: Color(0xff167755), buttonCornerRadius: 8, textFieldCornerRadius: 0, ), ), onSuccess: ( String inquiryId, InquiryAttributes attributes, InquiryRelationships relationships, ) async […]

shop_controller.dart

class ShopController extends GetxController{ late IProductService _productService; var isLoading = false.obs; List? productList = List.empty().obs; @override void onInit() { _productService = ProductService(Dio(BaseOptions( responseType: ResponseType.json, baseUrl: ‘https://fakestoreapi.com’))); fetchProducts(); super.onInit(); } void fetchProducts() async { isLoading(true); var products = await _productService.getAllProducts(); if(products != null){ productList = products; } isLoading(false); } }

show_view.dart

class ShopView extends StatelessWidget { final ShopController shopController = Get.put(ShopController()); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text(‘Shop App’), ), body: buildObxBody(context), ); } Obx buildObxBody(BuildContext context) { return Obx(() { return shopController.isLoading.value ? Center(child: CircularProgressIndicator()) : buildShopGridView(context); }); }

show_view_getx.dart

class ShopView extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text(‘Shop App’), ), body: buildGetxBody(context), ); } GetX buildGetxBody(BuildContext context) { return GetX( init: ShopController(), initState: (_) {}, builder: (controller) { return controller.isLoading.value ? Center(child: CircularProgressIndicator()) : buildShopGridView(context,controller); }, ); }

WIP dice formula parser

import ‘dart:math’; /// A [DiceParser] parses a dice formula into an AST. /// /// Throws [DiceParserException]s if the formula cannot be parsed. /// /// The formula grammar is modelled after Foundry VTT. Currently support /// for `{,}`, math functions, variables with `.`, dropping dice, /// counting evens, odds or failures, deducting or subtracting failures, /// […]