Skip to content

Instantly share code, notes, and snippets.

@abhaysood
abhaysood / main.dart
Created May 26, 2021 08:25
Flutter Diagnosticable demonstration
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@abhaysood
abhaysood / diagnosticable_properties_1.dart
Created May 28, 2021 12:49
Blog: Enrich the Flutter Inspector with Diagnosticable properties
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(IntProperty('_counter', _counter));
}
@abhaysood
abhaysood / diagnosticable_properties_3.dart
Created May 28, 2021 12:51
Blog: Enrich the Flutter Inspector with Diagnosticable properties
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(IntProperty('_counter', _counter));
properties.add(DiagnosticsProperty<MyColorScheme>('myColorScheme', _myColorScheme));
_myColorScheme.debugFillProperties(properties);
}
@abhaysood
abhaysood / diagnosticable_properties_2.dart
Last active May 28, 2021 12:53
Blog: Enrich the Flutter Inspector with Diagnosticable properties
class MyColorScheme with Diagnosticable {
final Color textColor;
final Color backgroundColor;
MyColorScheme(this.textColor, this.backgroundColor);
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(ColorProperty('textColor', textColor));
@abhaysood
abhaysood / diagnosticable_properties_complete_code.dart
Last active May 28, 2021 13:03
Blog: Enrich the Flutter Inspector with Diagnosticable properties
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@abhaysood
abhaysood / inherited_widget_issue.dart
Created June 9, 2021 09:46
inherited_widget_issue
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const DemoApp());
}
class DemoApp extends StatefulWidget {
const DemoApp({Key? key}) : super(key: key);
@abhaysood
abhaysood / main.dart
Last active September 28, 2021 16:27
Countdown Timer - Part 1
import 'dart:async';
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
@abhaysood
abhaysood / main.dart
Created September 28, 2021 16:29
Countdown Timer - Part 2
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
@abhaysood
abhaysood / main.dart
Last active September 29, 2021 06:37
Trigger semantics action in widget tests (medium blog)
import 'package:bug/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tap action', (WidgetTester tester) async {
await tester.pumpWidget(MyApp());
final helloWorldTextFinder = find.text("Hello World!");
@abhaysood
abhaysood / main.dart
Last active October 4, 2021 02:34
Testing a semantic announcement in Flutter
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
child: Text("announce"),