This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| extension NavigationExtension on BuildContext { | |
| Future<void> navigateTo(String routeName, {Object? arguments}) { | |
| return Navigator.pushNamed(this, routeName, arguments: arguments); | |
| } | |
| } | |
| void main() { | |
| runApp(MaterialApp( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| int? hexToInteger(String hex) => int.tryParse(hex, radix: 16); | |
| Color contrastColor(Color color) { | |
| final Brightness brightness = ThemeData.estimateBrightnessForColor(color); | |
| return brightness == Brightness.dark ? Colors.white : Colors.black; | |
| } | |
| extension StringColorExtensions on String { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Vehicle { | |
| //Defaults to car | |
| String get type => "car"; | |
| void drive() { | |
| print("You're driving a $type."); | |
| } | |
| } | |
| class Tractor implements Vehicle { | |
| @override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:async'; | |
| import 'dart:convert'; | |
| import 'dart:math'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:http/http.dart' as http; | |
| final random = Random(); | |
| void main() => runApp(const MyApp()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Programming is too easy. What if we wrote functions like this? | |
| //Instead of just calling the function, we create types to bundle | |
| //up the arguments and then pass the type to the function that accepts | |
| //a generic type. | |
| // | |
| //This is the essence of the Bloc pattern. | |
| class AdditionArguments { | |
| final num a; | |
| final num b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Programming is too easy. What if we wrote functions like this? | |
| //Instead of just calling the function, we create types to bundle | |
| //up the arguments and then pass the type to the function that accepts | |
| //a generic type. | |
| // | |
| //This is the essence of the Bloc pattern. | |
| sealed class Event {} | |
| class AdditionArguments extends Event { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() => runApp( | |
| MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| body: Center( | |
| child: FutureBuilder( | |
| future: Future<String>.delayed( | |
| const Duration(seconds: 3), () => 'Hello World!'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (int a, int b) returnMulti() => (1, 2); | |
| void main() { | |
| var numbers = returnMulti(); | |
| var dayNumber = switch (numbers) { | |
| (int a, int b) when a == 1 && b == 2 => 'One and Two', | |
| (_, _) => 'Default' | |
| }; | |
| print(dayNumber); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:math'; | |
| sealed class Shape {} | |
| class Square extends Shape { | |
| Square(this.length, this.width); | |
| final double length; | |
| final double width; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class Animal { | |
| String get name; | |
| } | |
| class Dog extends Animal { | |
| @override | |
| String get name => 'Spot'; | |
| } | |
| class Cat extends Animal { |