Skip to content

Instantly share code, notes, and snippets.

@EdsonBueno
EdsonBueno / tip_calculator.dart
Created July 17, 2020 12:08
Adding Input Widgets to the TipCalculator Widget from Hot Tip
BillTextField(
// 1
onChanged: (newAmount) {
// 2
setState(() {
_billAmount = newAmount;
});
},
),
// 3
@EdsonBueno
EdsonBueno / tip_calculator.dart
Created July 17, 2020 12:07
Creating the TipCalculator Widget From Hot Tip
import 'package:flutter/material.dart';
import 'package:hottip/components/moody_waiter_image.dart';
class TipCalculator extends StatefulWidget {
// 1
@override
State<StatefulWidget> createState() => _TipCalculatorState();
}
class _TipCalculatorState extends State<TipCalculator> {
@EdsonBueno
EdsonBueno / main.dart
Created July 17, 2020 12:06
Creating the App Widget from Hot Tip
class _HotTipApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 1
return MaterialApp(
home: _HomePage(),
theme: ThemeData(
// 2
primaryColor: Color.fromRGBO(144, 223, 170, 1),
),
@EdsonBueno
EdsonBueno / main.dart
Created July 17, 2020 12:05
Gist from Flutter Introduction Tutorial
// 1
class _HomePage extends StatelessWidget {
// 2
@override
Widget build(BuildContext context) {
// 3
return Scaffold(
appBar: AppBar(
title: Text(
'Hot Tip',
class CharacterListBloc {
CharacterListBloc() {
// The return type of the `listen` func is a `StreamSubscription`. You need
// to store your subscriptions for being able to access and cancel
// them if the widget (and consequently the BLoC) gets disposed.
// We call "listen" twice in this BLoC, so we have two subscriptions. In
// order to manage them together, we add both to a `CompositeSubscription`.
_subscriptions
// The '..' syntax is a Dart feature called cascade notation.
@EdsonBueno
EdsonBueno / build_method_with_bloc.dart
Created March 21, 2020 20:41
Example of a widget's build method using BLoC
@override
Widget build(BuildContext context) =>
Scaffold(
appBar: AppBar(
title: const Text('Characters'),
),
// We could be listening the BLoC's Stream on the initState method,
// storing the data on a variable whenever it arrives, and then calling
// setState to force the widget to rebuild, but instead, we're using
// this `StreamBuilder` helper class which does it all for us.
@EdsonBueno
EdsonBueno / character_list_page.dart
Last active March 18, 2020 13:17
Simple list showcasing the FocusDetector Widget
/// Fetches and displays a list of characters' summarized info.
class CharacterListPage extends StatefulWidget {
@override
_CharacterListPageState createState() => _CharacterListPageState();
}
class _CharacterListPageState extends State<CharacterListPage> {
Object _activeCallbackIdentity;
List<CharacterSummary> _characterSummaryList;
void main() {
FluroRouter.appRouter
// The '..' syntax is a Dart feature called cascade notation.
// Further reading: https://dart.dev/guides/language/language-tour#cascade-notation-
..define(
// The '/' route name is the one the MaterialApp defaults to as our initial one.
'/',
// Handler is a custom Fluro's class, in which you define the route's
// widget builder as the Handler.handlerFunc.
handler: Handler(
// This is how we push a new page using named routes. It could be called
// when the user selects an item from the character list.
void pushNewPage(BuildContext context, CharacterSummary character) {
Navigator.pushNamed(
context,
'character-details',
// Since we use the same Navigator.pushNamed
// function to every page we wanna push, the below `arguments`
// parameter type is `Object`, and there's nothing
// forbidding me to give it a `boolean` where we would