Skip to content

Instantly share code, notes, and snippets.

@stegrams
stegrams / linked_dropboxes.dart
Created March 28, 2021 23:42
Linked dropboxes. Changing the selected value of the first, triggers the items replacement of the second
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
@stegrams
stegrams / smoothies_json_decode.dart
Last active December 30, 2020 12:37
Decoding a JSON response in a concise way (version 1) and in a more "official way" (version 2)
// Version 2: The official way based on https://jsontodart.com converter, with a grain of my salt
import 'dart:convert';
void main() {
List<SmoothieModel> smoothies = jsonDecode(json_str)
.map<SmoothieModel>((s) => SmoothieModel.fromJson(s))
.toList();
print(smoothies);
}
@stegrams
stegrams / dialog_dismiss_latency.dart
Last active August 15, 2020 13:04
Unable to reproduce a question's dialog freeze after user response.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. 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/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@stegrams
stegrams / response_after_stateful_disposal.dart
Last active June 7, 2020 23:40
When setState called after await completion, usually there is not state to update. This an attempt to amend the issue.
import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'dart:html';
import 'package:flutter/material.dart';
Future<String> fetchHttpRes(int id) async {
final f1 = 'first_name', f2 = 'last_name', timeoutSec = 300;
final url = 'https://reqres.in/api/users/$id?delay=$id';
@stegrams
stegrams / show_form_dialog.dart
Last active June 2, 2020 23:37
Show a form as custom dialog and collect the field values.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
@immutable
class CategoryModel {
const CategoryModel({this.name, this.keywords});
final String name;
final String keywords;
@stegrams
stegrams / calculated_textformfield.dart
Last active June 2, 2020 01:30
A form field that it's value is calculated based on the values of two others.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
@stegrams
stegrams / anim_map_location.dart
Last active May 28, 2020 19:13
Map location with an animated wave.
import 'package:flutter/material.dart';
import 'dart:async';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@stegrams
stegrams / path_combine_intersect.dart
Last active May 24, 2020 11:39
Shape rendering and intersection with Path and Path.combine.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@stegrams
stegrams / hack_no_uniform_border_radius.dart
Last active May 25, 2020 00:15
A small hack to apply circular radius to an uniform border.
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@stegrams
stegrams / variable_field_number_form.dart
Created May 17, 2020 10:55
A minimal form sample with adjustable number of fields.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Form Demo',
home: MyHomePage(),