0% found this document useful (0 votes)
63 views74 pages

Flutter in Action 1st Edition Eric Windmill - The Full Ebook With All Chapters Is Available For Download Now

The document provides information about the book 'Flutter in Action' by Eric Windmill, which covers various aspects of Flutter development, including widget lifecycles, user interaction, state management, and working with data. It outlines the structure of the book, including its parts and chapters, and offers insights into the benefits of using Flutter for mobile app development. Additionally, it includes details about the publisher, Manning Publications, and how to order the book.

Uploaded by

kiplesrhoder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views74 pages

Flutter in Action 1st Edition Eric Windmill - The Full Ebook With All Chapters Is Available For Download Now

The document provides information about the book 'Flutter in Action' by Eric Windmill, which covers various aspects of Flutter development, including widget lifecycles, user interaction, state management, and working with data. It outlines the structure of the book, including its parts and chapters, and offers insights into the benefits of using Flutter for mobile app development. Additionally, it includes details about the publisher, Manning Publications, and how to order the book.

Uploaded by

kiplesrhoder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

Flutter in Action 1st Edition Eric Windmill

https://ebookmeta.com/product/flutter-in-action-1st-edition-
eric-windmill/

OR CLICK HERE

DOWLOAD EBOOK

Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com


Eric Windmill
Foreword by Ray Rischpater

MANNING

www.allitebooks.com
Widget Lifecycles

Stateless widget Stateful widget

Constructor Constructor

build() createState()
Rebuilds when Produces a state object
configuration
changes

State object

(Mounted)

initState()

(Dirty state)

widgetDidUpdate() build() setState()

(Clean state)
When it receives When internal state
new configuration changes
dispose()

www.allitebooks.com
Flutter in Action

ERIC WINDMILL
FOREWORD BY RAY RISCHPATER

MANNING
SHELTER ISLAND

www.allitebooks.com
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: [email protected]

©2020 by Manning Publications Co. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in


any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.

Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.

Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without the use of elemental
chlorine.

Acquisitions editor: Brian Sawyer


Manning Publications Co. Development editor: Susanna Kline
20 Baldwin Road Technical development editor: John Guthrie
PO Box 761 Review editor: Aleks Dragosavljević
Shelter Island, NY 11964 Production editor: Anthony Calcara
Copyeditor: Tiffany Taylor and Frances Buran
Proofreader: Melody Dolab
Technical proofreader: Gonzalo Huerta-Cánepa
Typesetter: Gordan Salinovic
Cover designer: Marija Tudor

ISBN 9781617296147
Printed in the United States of America

www.allitebooks.com
brief contents
PART 1 MEET FLUTTER ................................................................1
1 ■ Meet Flutter 3
2 ■ A brief intro to Dart 24
3 ■ Breaking into Flutter 54

PART 2 FLUTTER USER INTERACTION, STYLES, AND ANIMATIONS .........95


4 ■ Flutter UI: Important widgets, themes, and layout 97
5 ■ User interaction: Forms and gestures 129
6 ■ Pushing pixels: Flutter animations and using
the canvas 158

PART 3 STATE MANAGEMENT AND ASYNCHRONOUS DART ................189


7 ■ Flutter routing in depth 191
8 ■ Flutter state management 212
9 ■ Async Dart and Flutter and infinite scrolling 236

PART 4 BEYOND FOUNDATIONS ..................................................265


10 ■ Working with data: HTTP, Firestore, and JSON 267
11 ■ Testing Flutter apps 292

iii

www.allitebooks.com
contents
foreword xv
preface xvii
acknowledgments xix
about this book xxi
about the author xxiv
about the cover illustration xxv

PART 1 MEET FLUTTER ......................................................1

1 Meet Flutter
1.1
3
Why does Flutter use Dart? 4
1.2 On Dart 5
1.3 Who uses Flutter? 6
1.4 Who should be using Flutter? 6
Teams, project leads, and CTOs 6 Individual developers 7

Code school students and recent CS grads 7 Open source


developers 7 People who value speed 7 People who are


■ ■

lazy 7 People who value control 7


1.5 Who this book is for 8

v
vi CONTENTS

1.6 Other mobile development options 8


Native development (iOS and Android) 8 ■
Cross-platform
JavaScript options 8
1.7 The immediate benefits of Flutter 10
No JavaScript bridge 10 Compile time 10
■ ■ ■
Write once, test
once, deploy everywhere 10 Code sharing 11 ■ ■
Productivity
and collaboration 11 Code maintenance 11
■ ■
The bottom
line: Is Flutter for you? 11
1.8 Future benefits of Flutter: Web apps and desktop apps 12
1.9 A brief intro to how Flutter works 12
Everything is a widget 14 ■
Composing UI with widgets 15
Widget types 16
1.10 Flutter rendering: Under the hood 18
Composing the widget tree and layout 20 ■
Compositing step 21
Paint to the screen 22
1.11 Final note 22
1.12 Summary 23

2 A brief intro to Dart


2.1 Hello, Dart! 25
24

Anatomy of a Dart program 26 ■


Adding more greetings 26
I/O and Dart libraries 28
2.2 Common programming concepts in Dart 29
Intro to Dart’s type system 30 Comments 32 Variables and ■ ■

assignment 33 Operators 34 Null-aware operators 34


■ ■

2.3 Control flow 36


if and else 37 switch and case

37 ■
Advanced switch
usage 38 Loops 40

2.4 Functions 41
Anatomy of a Dart function 41 Parameters 42 Default ■ ■

parameter values 43 Advanced function concepts 43


Lexical scope 45
2.5 Object-oriented programming (in Dart) 45
Classes 46 Constructors 48 Inheritance 49
■ ■ ■
Factories
and named constructors 50 Enumerators 51 ■

2.6 Summary 53
CONTENTS vii

3 Breaking into Flutter


3.1
54
Intro to the counter app 55
Flutter project structure 56 Anatomy of a Flutter app 56

Again, everything is a widget 57 The build method 58


The new and const constructors in Flutter 59 Hot reload 59 ■

3.2 Widgets: The widget tree, widget types, and the State object 60
Stateless widgets 61 ■
Stateful widgets 62 ■
setState 64
initState 66
3.3 BuildContext 67
3.4 Enhancing the counter app with the most important
widgets 68
RaisedButton 68
3.5 Favor composition in Flutter (over inheritance) 69
What is composition? 69 ■
An example of composition in
Flutter 71
3.6 Intro to layout in Flutter 72
Row and Column 72 Layout constraints in Flutter 74

RenderObject 74 RenderObject and constraints 75


RenderBoxes and layout errors 75 Multi-child widgets 76


Icons and the FloatingActionButton 78 Images 80 ■

Container widget 81
3.7 The element tree 83
Elements and widgets 85 Exploring the element tree with an

example 86 The element tree and State objects 88 Widget


■ ■

keys 90
3.8 A final note 92
3.9 Summary 93

PART 2 FLUTTER USER INTERACTION, STYLES,


AND ANIMATIONS ...................................................95

4 Flutter UI: Important widgets, themes, and layout


4.1 Setting up and configuring a Flutter app 99
97

Configuration: pubspec.yaml and main.dart 99


SystemChrome 101
viii CONTENTS

4.2 Structural widgets and more configuration 102


MaterialApp widget 102 ■
The Scaffold widget 104 ■
AppBar
widget 106
4.3 Styling and themes in Flutter 108
Theme widget 108 MediaQuery and the of method 110

ScreenAwareSize method 111


4.4 Common layout and UI widgets 112
Stack widget 112 ■
Table widget 116 ■
TabBar widget 122
4.5 ListView and builders 126

5 User interaction: Forms and gestures


5.1 User interaction and gestures
129
130
The GestureDetector widget 130 GestureDetector in ■

practice 131 The Dismissible widget 134


5.2 Flutter forms 136


The Form widget 137 GlobalKey<FormState> 138 The structure
■ ■

of the AddCityPage form 138 Implementing the form in the weather


app 140
5.3 FormField widgets 141
The TextFormField widget 142 The DropdownFormButton ■

widget 143 Generic form fields 146


5.4 Form UI and working with focus nodes 147


InputDecoration 147 ■
Improving the UI with FocusNodes 149
5.5 Managing form state with form methods 151
Form.onChange 152 ■
FormState.save 153
Form.onWillPop 155
5.6 Summary 157

6 Pushing pixels: Flutter animations and using the canvas


6.1 Introducing Flutter animations 159
158

Tweens 160 Animation curves 161 Ticker providers 162


■ ■

AnimationController 162 AnimatedWidget 163 Implement


■ ■

ing the animation controller and tween for the background 166
6.2 CustomPainter and the canvas 172
The shapes used to make up the clouds 173 Defining the ■

CustomPainter and the Paint object 173 The CustomPainter ■

paint method 175


CONTENTS ix

6.3 Staggered animations, TweenSequence, and built-in


animations 179
Creating a custom animation state class 179 Built-in animation

widgets: SlideTransition 182 Building animations for the


Clouds widget 184 TweenSequence 185


6.4 Reusable custom color transition widgets 187

PART 3 STATE MANAGEMENT AND ASYNCHRONOUS DART ......189

7 Flutter routing in depth


7.1 Routing in Flutter 192
191

The Farmers Market app 192 ■


The app source code 193
7.2 Declarative routing and named routes 193
Declaring routes 194 Navigating to named routes 195

MaterialDrawer widget and the full menu 197 Menu items ■

and the appropriate widgets: ListView and ListItems 198


NavigatorObserver: Highlighting the active route with
RouteAware 201
7.3 Routing on the fly 204
MaterialRouteBuilder 204 ■
showSnackBar, showBottomSheet,
and the like 205
7.4 Routing animations 209
7.5 Summary 211

8 Flutter state management


8.1 Deep dive into StatefulWidgets
212
213
The widget tree and the element tree 213 ■
The StatefulWidget
lifecycle and when to do what 214
8.2 Pure Flutter state management: The InheritedWidget 216
Creating a Central Store wth an InheritedWidget/StatefulWidget
team 218 The inheritFromWidgetOfExactType and of

methods 218 Use the of method to lift up state 222


State management patterns beyond Flutter 224


8.3 Blocs: Business Logic Components 225
How do blocs work? 227 Implementing the bloc

architecture 228 Intro to streams and async Dart



231
Implementing streams in the CartBloc 232
8.4 Summary 235
x CONTENTS

9 Async Dart and Flutter and infinite scrolling


9.1 Async Dart 237
236

Future recap 237 The async/await keywords 239 Catching


■ ■

errors with futures 240 Catching errors with try and catch 241

9.2 Sinks and streams (and StreamControllers) 242


Anatomy of the observer pattern with Dart streams 243
Implementing streams 243 Broadcasting streams 245

Higher-order streams 247


9.3 Using streams in blocs 250
Blocs use inputs and outputs 250 ■
Implementing a bloc input 253
9.4 Async Flutter: StreamBuilder 254
9.5 Infinite and custom scrollable widgets 255
CustomScrollView and slivers 256 Catalog widget scroll view 256

The SliverGrid widget 260 Delegates 260 Custom slivers 261


■ ■

PART 4 BEYOND FOUNDATIONS ........................................265

10 Working with data: HTTP, Firestore, and JSON


10.1 HTTP and Flutter 268
267

HTTP package 269 ■


GET requests 269
10.2 JSON serialization 270
Manual serialization 271 Auto-generated JSON serialization 275

Updating the Todo class 275 Bringing it all together in the UI 277

10.3 Working with Firebase in Flutter 281


Installing Firestore 282 Create a Firestore project 283

Configure your app 283 Add Firebase to your pubspec 286


Using Firestore 286


10.4 Dependency injection 288
10.5 Summary 291

11 Testing Flutter apps


11.1 Tests in Flutter
292
293
Dart unit tests 293 Using mockito to test methods that need external

dependencies 297 Flutter widget tests 300 Flutter integration


■ ■

tests 303 Performance profiling integration tests 307


11.2 Accessibility with the semantics widgets 310


11.3 Next steps with Flutter 311
CONTENTS xi

appendix A Installation: Dart2 313


appendix B The Pub package manager 318
appendix C Flutter for web developers 321
appendix D Flutter for iOS developers 324
appendix E Flutter for Android developers 328
index 331
foreword
One of the things the Flutter team is deeply grateful for is the supportive community
of Flutter developers. For nearly any question you may have, you can find an answer
on Stack Overflow, Medium, or even someone’s GitHub account. Many answers come
with fully working sample code with a license that lets you use the code right in your
application. We see this spirit of cooperation and camaraderie as crucial to making
you successful with Flutter.
Until now, though, there’s been little material that you can actually hold in your
hands and work through at your desk or in the evenings as you learn how to use Flut-
ter. While blogs, Medium, and online documentation have been a paradigm shift for
book publishers, especially in computing, there’s still a need for long-form material
on topics, and Flutter is no exception.
This is why this book is so important. There are things you can’t get from a five-
hundred-word Medium post or a snippet of code on Stack Overflow. Thinking deeply
about things like how your application manages its state requires you to understand
the platform deeply. In this book, you’ll not only see how to use Flutter, but you’ll
understand why using Flutter in the ways Eric and people online say to actually works
in practice.
Eric covers many of the things that developers have found challenging when moving
to Flutter. Between these pages you’ll learn about how layout works, how to build
widgets that interact with users, and how to build complex applications that span
multiple pages and carry complex application sate. For users new to Dart, there’s an
entire chapter on how Dart handles asynchronicity. Because today’s mobile

xiii
xiv FOREWORD

applications are communicating applications, you’ll also see how to handle JSON with
HTTP backends, and as a bonus, how to use Firestore to manage data storage. And, to
wrap things up, there’s a whole chapter on testing.
Throughout, Eric’s taken the time to explain not just what, but why. I urge you to
do the same—while you can dip in and out of a chapter to get just the morsel of infor-
mation you need, why not pause for a minute and savor the experience of actually
holding this book and going deeper? Doing so will make you a better programmer
with Flutter and pay dividends elsewhere in your life as you slow down and remember
how to not just learn, but master a new technology.
I and the entire Flutter team are excited to see what you build with Flutter. Thank
you for trusting us with your ideas.
—RAY RISCHPATER
TECHNICAL PROGRAM MANAGER, FLUTTER
GOOGLE
preface
When I started using Flutter in September 2017, it was in an alpha stage. I started
using it because my boss told me to. I had no opinions about it because I had never
heard of it. I hadn’t even heard of Dart, which had been around for nearly a decade
by then. But—and this probably isn’t a spoiler— I got hooked immediately. Not only is
the end product of the highest quality, but the development process is perhaps the
most enjoyable of any SDK that I’ve used. The tooling, the community, the API, and
the Dart language are all a joy to participate in.
That’s why I’ve written this book. I legitimately believe that Dart and Flutter are the
near-future, gold-standard of application development. And I’ve written a book that I
think will get any developer from zero to one with Flutter. This book is half tutorial,
half spreading-the-good-word.
Nearly two years after starting to use Flutter, I’m now working at my second job
that lets me build a Flutter app everyday, and my enthusiasm hasn’t wained. Flutter is
the truth.
In those two years, Flutter has grown quite a bit. It went from alpha to beta to ver-
sion 1, and it’s now stable. Dart went from version 1 to 2, and is now putting a lot of
effort into making it an ideal language to write modern UIs in. And now, at the time
of this writing, Flutter for web is in technical preview. It looks like it’ll only get more
exciting.
Flutter is going to keep improving, but the foundation is now set. And that’s why I
think this book can really help. No matter how it grows, this book will get you started
and build your Flutter foundation.

xv
xvi PREFACE

There is no shortage of resources for learning Flutter. My goal with this book, how-
ever, is to cover the process in one go. You’ll learn about Dart a bit, and you’ll learn
about Flutter a lot. By the end of the book, you’ll have experience writing a mobile
app from scratch. This book covers all of the foundational knowledge you need to
write beautiful, buttery-smooth mobile apps with Flutter. I’ll cover UI and layout, ani-
mations and styling, network requests, state management, and more.
acknowledgments
This is the first book I’ve written. One of the things I’ve learned in the process is just
how many people are involved. I am truly only one of many, many people who put a
lot of work into this.
First, I’d like to thank two of my former bosses and colleagues, Matthew Smith and
John Ryan. When they hired me at AppTree, I hadn’t heard of Flutter or Dart. And
more, I still had (and continue to have) a lot to learn about building software. They
taught me everything I know, and were patient the entire time. It is the best job I’ve
ever had, and it allowed me to fall in love with Dart and Flutter.
I’d like to acknowledge my editor at Manning, Susanna Kline, for two reasons.
First, I had no clue about how to write a book. Susanna has been patient, yet per-
sistent. She’s also been kind, yet honest. All those qualities certainly allowed me to
write the best book I could. And secondly, she really let me explore and write the book
I wanted to write. Which is why, at the end of this process, I’m still loving it.
I’d like to thank all the reviewers, colleagues, and friends who’ve read the manu-
script and given feedback. This includes those who’ve commented over at the Man-
ning book forum. I can say with 100% certainty that the book would’ve suffered
without the feedback. Specifically, I’d to thank all the reviewers: Andy King, Damian
Esteban, David Cabrero Souto, Edwin Kwok, Flavio Diez, Fred Heath, George Onof-
rei, Godfred Asamoah, Gonzalo Huerta-Cánepa, Jacob Romero, Joel Kotarski, Jose
San Leandro, Kumar Unnikrishnan, Martin Dehnert, Nitin Gode, Paul Brown, Petru
Bocsanean, Pietro Maffi, Samuel Bosch, Sander Zegvelt, Serge Simon, Thamizh Arasu,
Willis Hampton, and Zorodzayi Mukuya.

xvii
xviii ACKNOWLEDGMENTS

Of course, I have to thank everyone who works on Flutter and Dart, as well as the
Flutter community online. This community has been by far the most pleasant, uplift-
ing, and friendly tech community I’ve ever been a part of.
Lastly, I want to thank the following dogs and cats that I know, who I used as exam-
ples through out the book: Nora, Odyn, Ruby, Doug, Harper, Tucker, Yeti, and Rosie.
(If you own one of these animals and you’re reading this, you get no royalties. Thank
you.)
about this book
Flutter in Action is a book about empowering everyone (and anyone) to create mobile
applications with the Flutter SDK and the Dart programming language. It focuses first
on understanding the who, what, why, and how of Flutter. Over the first few chapters,
I hope to convince you that Flutter is worth your time, and ease you into the basics.
Following that, I take a deep dive into the UI: layout, routing, animations, and more.
And then I spend time on state management and the tougher concepts, like asynchro-
nous programming with Flutter in Dart. I finish with some short chapters about HTTP
and Firebase, as well as testing.
Importantly, this book is focused on Flutter-specific contents. I will not use third-
party resources to develop niche apps or solve niche problems. This entire book uses
only a handful of libraries outside of Flutter.

Who should read this book


This book is for application developers that want to write Flutter apps. Whether you
have experience with writing web apps, native mobile apps, Xamarin, or something I
don’t even know about yet, this book is for you. The important thing for you to under-
stand is how modern applications work. I don’t expect you to know how to write code
across the whole stack, only that you know what a modern stack consists of.
There are a ton of resources and blog posts out there that contain much of this
information. The point of this book is to bring everything together in one easy-to-follow
format.

xix
xx ABOUT THIS BOOK

How this book is organized


This book has eleven chapters over four sections.
Part 1 is meant to prepare you to dive in:

Chapter 1 explains what Flutter is and why we, mobile developers, should care.
It also gets into the basics of Flutter.

Chapter 2 departs a bit and covers (briefly) the Dart programming language, as
well as an intro into object-oriented programming (OOP). If you know about
Dart, or are comfortable picking up a new language, you can skip this chapter.

Chapter 3 takes a dive into how Flutter works under the hood and the basics of
writing Flutter code. By the end of this chapter, you will have your environment
set up, as well as have a basic understanding of writing a Flutter app.
Part 2 covers all things UI. It uses a dumb, stateless app to cover forms, animations,
and more:

Chapter 4 covers all the basic widgets in Flutter. This chapter is all about the
base features that you’ll likely use in every Flutter app you ever write.

Chapter 5 is about forms and gestures. In short, this chapter explains how the
user interacts with the app you’re writing.

Chapter 6 is about making the app beautiful. It covers painting to the canvas
and takes a deep dive into animations in Flutter.
Part 3 is all about state management. Some of this section is where many of the tough-
est concepts come into play. It uses an e-commerce app as the example:

Chapter 7 is all about routing. It includes passing state from one route to
another, as well as routing animations.

Chapter 8 is about state management. It’s the first chapter to cover some con-
cepts that aren’t exactly Flutter-specific. It includes new widget types, like the
InheritedWidget, as well as using the bloc pattern to manage state.

Chapter 9 is my favorite, I think. It covers asynchronous Dart concepts like
streams and how to incorporate those concepts into Flutter. Spoiler: Flutter
supports those features as first-class citizens.
Part 4 is called “Beyond the Foundation” because it’s about moving out of your IDE
and into subjects that can apply to any SDK: network calls, Firebase, working with
JSON, and testing:

Chapter 10 is all about using outside resources. It covers HTTP, Firebase, and
JSON serialization.

Chapter 11 is about everyone’s favorite topic: testing. It includes Flutter’s built-
in testing framework, as well as mockito and the Flutter driver.
In general, this book is meant to build up from one chapter to another. It’s a tutorial-
style book, which means if you “choose your own adventure,” there may be important
pieces missed.
ABOUT THIS BOOK xxi

About the code


This book contains (mostly) large blocks of code, rather than short snippets. There-
fore, most of the examples are annotated and explained for each code listing. Because
this book is about writing entire apps, the code for each section is highly reliant on
the entire app. So, at the beginning of most code snippets, I’ve left a comment, follow-
ing // on the top line, of where you can find the code snippet in the source code of
the app.
You can find the source code for these example apps by downloading it from the
publishers website at https://www.manning.com/books/flutter-in-action.

liveBook discussion forum


Purchase of Flutter in Action includes free access to a private web forum run by Man-
ning Publications where you can make comments about the book, ask technical ques-
tions, and receive help from the author and from other users. To access the forum, go
to https://livebook.manning.com/#!/book/flutter-in-action/discussion. You can also
learn more about Manning’s forums and the rules of conduct at https://livebook
.manning.com/#!/discussion.
Manning’s commitment to our readers is to provide a venue where a meaningful
dialogue between individual readers and between readers and the author can take
place. It is not a commitment to any specific amount of participation on the part of
the author, whose contribution to the forum remains voluntary (and unpaid). We sug-
gest you try asking the author some challenging questions lest his interest stray! The
forum and the archives of previous discussions will be accessible from the publisher’s
website as long as the book is in print.
about the author
Eric Windmill is a software engineer, who’s focused largely on client-side applications.
He’s been lucky enough to work with Flutter since its very early days, at multiple com-
panies now. He is the author of FlutterByExample.com. He is passionate about help-
ing open the doors and removing barriers into tech.

xxii
about the cover illustration
The figure on the cover of Flutter in Action is captioned “Femme Tattare de Kazan,” or
“Kazan Tattar Woman” in English. The illustration is taken from a collection of works
by many artists, edited by Louis Curmer and published in Paris in 1841. The title of
the collection is Les Français peints par eux-mêmes, which translates as The French People
Painted by Themselves. Each illustration is finely drawn and colored by hand and the
rich variety of drawings in the collection reminds us vividly of how culturally apart the
world’s regions, towns, villages, and neighborhoods were just 200 years ago. Isolated
from each other, people spoke different dialects and languages. In the streets or in
the countryside, it was easy to identify where they lived and what their trade or station
in life was just by their dress.
Dress codes have changed since then and the diversity by region, so rich at the
time, has faded away. It is now hard to tell apart the inhabitants of different conti-
nents, let alone different towns or regions. Perhaps we have traded cultural diversity
for a more varied personal life—certainly for a more varied and fast-paced technolog-
ical life.
At a time when it is hard to tell one computer book from another, Manning cele-
brates the inventiveness and initiative of the computer business with book covers
based on the rich diversity of regional life of two centuries ago, brought back to life by
pictures from collections such as this one.

xxiii
Part 1

Meet Flutter

T he first section of this book is in three chapters, and it’s meant to prepare
you to build full-blown Flutter apps. In particular, this includes three subjects.
First, I’ll introduce all things Flutter in chapter 1. This includes the whos,
whats, whys, and hows: how it works, why it’s worth investing in, and the mental
model needed to use the SDK. This chapter is largely conceptual and involves lit-
tle code.
I also devote a chapter to Dart, the programming language that Flutter uses.
I like to call Dart Java Lite. And I mean that in a great way. If you’re comfortable
with object-oriented and strongly typed languages, you can probably just skim
this chapter.
Then, in chapter 3, we’ll explore Flutter itself. This chapter uses a simple
Flutter example app to explain how Flutter works, both from the perspective of
how you write code, as well as some more explanations of how the engine works.
By the end of chapter 3, you’ll be set up, comfortable with the SDK, and ready to
start building a Flutter app. If I did a good job, you’ll also understand what’s
under the hood.
Meet Flutter

This chapter covers


 What is Flutter?
 What is Dart?
 Why does Flutter use Dart?
 When is Flutter the right tool (or the wrong tool)?
 A brief intro to how Flutter works

Flutter is a mobile SDK, built and open sourced by Google; and at its core, it’s
about empowering everyone to build beautiful mobile apps. Whether you come
from the world of web development or native mobile development, Flutter makes it
easier than ever to create mobile apps in a familiar, simplified way. Flutter is special
in that it makes it truly possible to “write once, and deploy everywhere.” As of this
writing, Flutter apps will deploy to Android, iOS, and ChromeOS. In the near
future, Flutter apps will also run as web apps and desktop apps on all major operat-
ing systems.
In short, Flutter is a truly complete SDK for creating applications. It’s a platform
that provides everything you need to build applications: rendering engine, UI com-
ponents, testing frameworks, tooling, router, and many more features. The conse-
quence is that you get to focus on the interesting problems in your app. You can

3
4 CHAPTER 1 Meet Flutter

focus specifically on the domain functionality, and everything else is taken care of.
The value that Flutter provides is astonishing.
In fact, that’s how I found myself here, writing this book. I had to learn Flutter
because of my job, and I loved it from the moment I started. I effectively became a
mobile developer overnight, because Flutter felt so familiar to my web development
background. (The Flutter team has said that they were influenced by ReactJS.)
Flutter isn’t only about being easy, though. It’s also about control. You can build
exceptional mobile apps using Flutter with a shallow knowledge of the framework. But
you can also create incredible and unique features, if you so choose, because Flutter
exposes everything to the developer.
This is a book about writing a (relatively) small amount of code and getting back a
fully featured mobile app that works on iOS and Android. In the grand scheme,
mobile app development is new. It can be a pain point for developers and companies
alike. But I believe Flutter has changed that (and that’s a hill I’m willing to die on).
This books has one goal: to turn you into a (happy) Flutter (and Dart) developer.

1.1 Why does Flutter use Dart?


Flutter apps are written in the programming language called Dart. I’ll describe Dart in
depth throughout the book, but for now, just know that all the code you write in a
Flutter app is Dart code. In fact, to us, the mobile developers, Flutter appears to be
nothing more than a Dart library.
Dart is also owned and maintained by Google. This may give you pause. There are
reasons to be skeptical of this choice: it’s not one of the hot languages of today, few
companies use it in production, and the community must be small. What gives? Is
Google just using it because it’s Google’s language? I imagine that played a role, but
there are practical reasons, too:
 Dart supports both just-in-time (JIT) compiling and ahead-of-time (AOT) com-
piling:
– The AOT compiler changes Dart into efficient native code. This makes Flut-
ter fast (a win for the user and the developer), but it also means that (nearly)
the entire framework is written in Dart. For you, the developer, that means
you can customize almost everything.
– Dart’s optional JIT compiling allows hot reloading to exist. Fast development
and iteration is a key to the joy of using Flutter.
 Dart is object-oriented. This makes it easy to write visual user experiences with
Dart, with no need for a markup language.
 Dart is a productive, predictable language. It’s easy to learn, and it feels familiar.
Whether you come from a dynamic language or a static language, you can get
up and running with ease.
And I think Google owning Dart is an advantage. In the last few years, Dart has made
great strides to be a nice language specifically for writing modern UIs. The type system
On Dart 5

and object orientation make it easy to reason about writing reusable components for
the UI. And Dart includes a few functional programming features that make it easier
to turn your data into pieces of UI. Finally, asynchronous, stream-based programming
features are first-class citizens in Dart. These features are used heavily in reactive pro-
gramming, which is the paradigm of today.
Lastly, Dart excels at being a language that’s easy to learn. As a coworker of mine
said about hiring, “We don’t have to find Dart people, only smart people.”

1.2 On Dart
Besides explaining Flutter in depth, I will also introduce the basics of Dart. Dart is a
programming language. And programming languages can be, as it turns out, hard to
learn. The fundamentals of Dart are similar to all higher-level languages. You’ll find
familiarity in Dart syntax if you’re coming from JavaScript, Java, or any other C-like
language. You’ll feel comfortable with Dart’s object-oriented design if you’re coming
from Ruby or Python.
Like all languages, though, the devil is in the details (and, as they say, doubly in the
bubbly). The joys of Dart and the complexity of writing good Dart code lie not in the
syntax, but in the pragmatics.
There’s good news, though. Dart excels at being a “safe” language to learn. Google
didn’t set out to create anything innovative with Dart. Google wanted to make a lan-
guage that was simple and productive and that could be compiled into JavaScript.
What Google came up with works well for writing UIs.
The fact that Flutter can compile to JavaScript is less relevant for Flutter develop-
ment, but it has had interesting consequences for the language. Originally, Dart was
created as a language for web development. The stretch goal was to include a Dart
runtime in the browser, as an alternative to JavaScript. Eventually, though, Google
decided to write a compiler instead. This means nearly every feature in Dart must fit
inside JavaScript semantically.
JavaScript is a unique language, and it isn’t necessarily feature-rich. It accom-
plishes what it needs to accomplish, without any extraneous bells and whistles (which
is a plus, in my opinion). So, in the past, Dart has been limited by what JavaScript can
do. The result is a language that feels more like Java but is less cumbersome to write.
(I like to jokingly call it “Java Lite,” which is a compliment.)
There is nothing particularly exciting about its syntax, and no special operators
will throw you for a loop. In Dart (unlike JavaScript), there is one way to say true:
true. There is one way to say false: false. If (3) { would make Dart blow up, but it’s
coerced to true in JavaScript.
In Dart, there are no modules (like C# and the like), and there is really only one
dynamic in which people write Dart code: object-oriented. Types are used in Dart,
which can be a hurdle if you’re coming from Ruby, Python, or JavaScript, but the type
system is not as strict as in many typed languages.
6 CHAPTER 1 Meet Flutter

All this is to say that Dart is a relatively easy language to learn, but you should take
the time you need to learn it. Writing an app in Flutter is writing Dart. Flutter is,
underneath it all, a library of Dart classes. There is no markup language involved or
JSX-style hybrid language. It’ll be much easier to be a productive Flutter developer if
you’re comfortable writing effective Dart code. I’ll cover Dart in depth in chapter 2.

1.3 Who uses Flutter?


At the time of writing, Flutter is used in production by big and small companies alike.
I’ve been lucky enough to use Flutter at work since September 2017, when the tech-
nology was still in its alpha stage. By the time you read this, Flutter will be in (at least)
version 1.9.0, and my previous company will have migrated all of our clients off of our
native apps and onto our Flutter app.
While this isn’t a book about me, I am going to tell you a bit about what I do, because
I want you to know that I’m confident in the future of Flutter. The company that I pre-
viously worked for is in the enterprise space. Its product is used by some big companies
like Stanford University, Wayfair, and Taylor Parts. The core product is a BYOD (bring
your own database) platform that lets customers plug in a few options and press a few
buttons, and it spits out mobile and web apps to manage work flows and business-
related enterprise issues. The mobile app supports offline usage, Esri maps, and real-
time feedback. We did all this with Flutter (on mobile) and Dart on the server side. The
point is this: don’t be afraid of the limitations of this cross-platform tool.
We weren’t the only ones using Flutter in production. As of this writing, Google
AdWords and Alibaba are both using Flutter in production. You can see more exam-
ples of who’s using Flutter (including an app I worked on for two years) on Flutter’s
website on the showcase page.1

1.4 Who should be using Flutter?


Regardless of your role at your company, or even if you’re building apps for fun, every-
one should consider Dart for their next project.

1.4.1 Teams, project leads, and CTOs


Flutter has proved, in front of my own eyes, that it increases productivity and collabo-
ration by orders of magnitude. Before Flutter, each time a new feature was introduced
to a product at my former company, it had to be written and maintained three times
by three different teams—three different teams that could hardly collaborate because
they had different skill sets.
Flutter solved that problem. Our three teams (web, iOS, and Android) became
one unified clients team. We all had the same skill set, and we could all collaborate
and lend helping hands.

1
You can find the showcase at https://flutter.dev/showcase.
Who should be using Flutter? 7

At my current job, we’re rewriting a native iOS client in Flutter for the same rea-
son. It allows us to be flexible and productive while offering users both iOS and
Android apps. After a failed attempt at a different, unnamed cross-platform solution,
Flutter has proven to be the ideal tool.

1.4.2 Individual developers


As developers, we often get starry-eyed and want to start a new project that will change
everything. The key to success with this sort of work is busting out the project quickly.
I can’t count how many times I was ready to start a new project and quit before I
began because of JavaScript build tools and setup. If you need to build an MVP fast,
and iterate quickly, Flutter just works.

1.4.3 Code school students and recent CS grads


Code schools are quite popular, and unfortunately for the graduates, that means there
are many grads fighting for the same junior-level jobs. My advice to anyone looking
for their first job is to build a portfolio that sets you apart. Having a published mobile
app with actual users will do that, and it’s easier than ever to achieve with Flutter.

1.4.4 Open source developers


Flutter is open source. Dart is open source. The tools and the libraries are open
source.

1.4.5 People who value speed


Flutter is for people who want to build an app quickly that doesn’t sacrifice perfor-
mance. By speed, I mean the speed at which you can write code and iterate, and the
speed at which Flutter builds. Thanks to hot reloading, Flutter rebuilds your applica-
tion in sub-second time as you’re developing.
I would also argue that Dart makes you more productive, adding more speed. Dart
is strictly typed and fully featured. Dart will save you from having to solve problems
that are already solved, and the syntax and tooling make debugging a breeze.

1.4.6 People who are lazy


I’m a lazy developer. If a problem is solved, I don’t want to waste time solving it again.
Flutter comes with a massive library of Material Design widgets that are beautiful and
ready to use out of the box. I don’t have to worry myself with designing and building
complicated pieces of a mobile app (such as a navigation drawer). I want to focus on
the business logic that makes my app unique.

1.4.7 People who value control


Although I’m lazy, I do want to know that if I need to, I can change anything about my
app. Flutter exposes every layer of the framework to the developer. If you need to write
some custom rendering logic, you can do that. You can take control of animations
8 CHAPTER 1 Meet Flutter

between frames. Every high-level widget in Flutter is a string that can be unspooled and
followed to the inner workings of the framework.

1.5 Who this book is for


This book assumes that you’ve developed an application before. That could be a web
app, a native mobile app, Xamarin, or something I don’t even know about. The
important thing for you to understand is how a modern application works. I don’t
expect you to know how to write code across the whole stack, only that you know what
a modern stack consists of. This book will focus on writing a mobile application in
Flutter, and I will throw around common terms like state, store, services, and so on.
If you meet those criteria, I can assume that you’re familiar with the common
threads across all programming languages. You don’t need to know Dart, but you do
need to know about basic data structures (Map, lists, and so on) and features of all
high-level languages (control flow, loops, and so on).
Finally, this book assumes that you know some high-level information about soft-
ware engineering in general. For example, Dart and Flutter operate completely in the
camp of the object-oriented paradigm.
This book is perfectly suitable for you if you’re a junior developer, a senior devel-
oper, or anywhere in between. The prerequisites are simply that you’ve worked on
large code bases before and you’re interested in learning Flutter.

1.6 Other mobile development options


Before I offer up unsolicited opinions on your other options, I want to make this crys-
tal clear: good developers think critically about which tools and technologies should
be used in every different situation. And Flutter is not the answer 100% of the time.
(But I will try hard to convince you otherwise.)

1.6.1 Native development (iOS and Android)


Your first choice is to write native apps for iOS and Android. This gives you maximum
control, debugging tools, and (potentially) the best performance. At a company, this
likely means you have to write everything twice: once for each platform. You probably
need different developers on different teams with different skill sets, and those devel-
opers can’t easily help each other.

1.6.2 Cross-platform JavaScript options


Your second option: cross-platform, JavaScript-based tools such as web views and React
Native. These aren’t bad options, either. The problems you experience with native
development disappear. Every frontend web developer on your team can chip in and
help; all they need are some modern JavaScript skills. This is precisely why large com-
panies such as Airbnb, Facebook, and Twitter have used React Native on core products.
Of course, there are some drawbacks. (You knew there would be drawbacks.) The
biggest is called the JavaScript bridge.
Other mobile development options 9

The first “mobile apps” to be built cross-platform were simply web views that ran on
WebKit (a browser rendering engine). These were literally embedded web pages. The
problem with this is basically that manipulating the DOM is very expensive and
doesn’t perform well enough to make a great mobile experience.
Some platforms have solved this problem by building the JavaScript bridge, which
lets JavaScript talk directly to native code. This is much more performant than the
web views, because it eliminates the DOM from the equation, but it’s still not ideal.
Every time your app needs to talk directly to the rendering engine, it has to be com-
piled to native code to “cross the bridge.” In a single interaction, the bridge must be
crossed twice: once from platform to app, and then back from app to platform, as
shown in figure 1.1.

YOUR APPLICATION DEVICE LAY


A ERS

PLATFORM RENDERING CANVAS


Application FRAMEWORK COMPARE RENDER
WIDGETS
layers WIDGETS Diffing
WIDGETS JavaScript
S Platform widgets PIPELINE
(i.e., Swift code) NATIVE ELEMENTS
algorithm bridge
d communicating
with device
rendering and events

Nativee code
Platform talks
crosses bridge
b to
Application layer to native code
APPLICATION talk to JavaScript
a
communication
COMPUTES D!
process P PE
CHANGES JavaScriptt crosses Native code tells TA
bridge to
o talk to platform to render
submit

native code
c

Figure 1.1 The JavaScript bridge is a major bottleneck to mobile frameworks in JavaScript. The JavaScript isn’t
compiled to native code and therefore must compile on the fly while the app is running.

Flutter compiles directly to ARM code when it’s built for production. (ARM is the pro-
cessor used in modern mobile devices, wearables, internet of things [IoT] devices,
and so on.) And Flutter ships with its own rendering engine. Rendering engines are
outside the scope of this book (and my knowledge, for that matter). Simply, though,
these two factors mean that your app is running natively and doesn’t need to cross any
bridge. It talks directly to native events and controls every pixel on the screen directly.
Compare the JavaScript bridge to figure 1.2, which represents a Flutter app.
The JavaScript bridge is a marvel of modern programming, to be sure, but it pres-
ents two big problems. First, debugging is hard. When there’s an error in the runtime
compiler, that error has to be traced back
across the JavaScript bridge and found in Flutter App Platform
RENDER

the JavaScript code. The second issue is COMPARE


CANVAS
performance. The JavaScript bridge is WIDGETS
EVENTS
expensive: each time a button in the app is
tapped, that event must be sent across the Figure 1.2 The Flutter platform, in the context
bridge to your JavaScript app. The result, of the JavaScript bridge
for lack of better term, is jank.
10 CHAPTER 1 Meet Flutter

Many of these cross-platform problems are solved with Flutter. Later in this chap-
ter, I’ll show you how.

1.7 The immediate benefits of Flutter


I’m going to make an assumption about you. Since you’re reading this book (and this
section), it follows that you’re curious about Flutter. It’s also likely that you’re skeptical.
The reasons you have for being skeptical are fair. It’s a new technology, and that
means breaking changes in the API. It means missing support for important features.
It seems possible that Google could abandon it altogether one day. Not to mention
the fact that Dart isn’t widely used, and many third-party libraries that you want may
not exist.
Now that I’ve pinned you, let me change your mind. The API likely will not
change, as the the company that’s developing Flutter and Dart uses Dart internally on
major revenue-generating apps such Google AdWords.
Dart has recently moved into version 2.5, which means it will be a long time until it
changes much. In the near future, there likely won’t be many breaking changes.
Finally, features are indeed missing, but Flutter gives you the complete control to
add your own native plugins. In fact, many of the most important operating system
plugins already exist, such as a Google Maps plugin, camera, location services, and
device storage. And new features are being added all the time. By the time you read
this, this paragraph may be irrelevant.

1.7.1 No JavaScript bridge


The JavaScript bridge, used in most cross-platform options, is a major bottleneck in
development and in your application’s performance. Scrolling isn’t smooth, applica-
tions aren’t always performant, and they’re hard to debug.
Flutter compiles to actual native code and is rendered using the same engine that
Chrome uses to render (called Skia), so there’s no need to translate Dart at runtime.
This means apps don’t lose any performance or productivity when running on a user’s
device.

1.7.2 Compile time


If you’re coming from native mobile development, one of your major pains is the
development cycle. iOS is infamous for its compile times. In Flutter, a full compile
generally takes less than 30 seconds, and incremental compiles take less than a second
thanks to hot reloading. At my day job, we develop features for our mobile client first
because Flutter’s development cycle allows us to move so quickly. Only when we’re
sure of our implementation do we write those features in the web client.

1.7.3 Write once, test once, deploy everywhere


Not only do you get to write your app one time and deploy to iOS and Android (and
soon, web!), you also only have to write your tests once. Dart unit testing is quite easy,
and Flutter includes a library for testing widgets.
The immediate benefits of Flutter 11

1.7.4 Code sharing


I’m going to be fair here: I suppose this is technically possible in JavaScript as well. But
it’s certainly not possible in native development. With Flutter and Dart, your web and
mobile apps can share all the code except each client’s views. You can use dependency
injection to run an AngularDart app and a Flutter app with the same models and con-
trollers. (And, in the very near future, Flutter will be able to target Web and Desktop,
too.) And obviously, even if you don’t want to share code between your web app and
your mobile app, you’re sharing all your code between the iOS and Android apps.
In practical terms, this means you are super productive. I mentioned that we
develop our mobile features first at my day job. Because we share business logic
between web and mobile, once the mobile feature is implemented, we only have to
write views for the web that expect the same controller data.

1.7.5 Productivity and collaboration


Gone are the days of separate teams for iOS and Android. In fact, whether you use
JavaScript in your web apps or Dart, Flutter development is familiar enough that all
your teams will be unified. It’s not a stretch by any means to expect a JavaScript web
developer to also effectively develop in Flutter and Dart. If you believe me here, then
it follows that your new unified team will be three times more productive.

1.7.6 Code maintenance


Nothing is more satisfying than fixing a bug once and having it corrected on all your
clients. Only in very specific cases is there a bug on the Flutter-produced iOS app and
not the Android one (and vice versa). In 100% of these cases, these bugs aren’t bugs,
but cosmetic issues, because Flutter follows device OS design systems in its built-in wid-
gets. Because these are issues like text size and alignment, they are trivial in the con-
text of using engineering time to fix them.

1.7.7 The bottom line: Is Flutter for you?


You can spend all day listening to people tell you the benefits or downfalls of any tech-
nology. At the end of the day, though, it’s all about the tradeoff. So should you care
about Flutter? I’ve sprinkled in the answer to this already, but let me give it to you
straight.
Are you an individual developer working on a side project or new product? Then the
answer is simple: yes. This is absolutely for you. The amount of time you’ll spend get-
ting up to speed with Dart and Flutter will pay off big time in the long run.
Are you a CTO deciding if your company should adopt the technology? Well, this
is a little more nuanced. If you’re starting a new project and trying to use the skills of
web developers, then absolutely. You’ll get better performance and a more cohesive
team, and all your developers (mobile and web), will be able to pick it up quickly.
However, if you have a big team of iOS and Android engineers, then probably not. If
you have the resources to not be concerned with keeping parity between your clients,
12 CHAPTER 1 Meet Flutter

then why rewrite them? Why gamble on a new technology? Flutter is about
empowering anyone to build native quality apps, but if you’re already empowered to
build native apps, it’s probably not for you. (This is why Airbnb famously abandoned
React Native.)
My final comment is this: you can be up and running with a new Flutter app in
about an hour from a standing start. If you already do iOS or Android development
on your machine, you likely have most of the tools needed already, and you can be up
and running in a matter of minutes. You might as well give it a try.

1.8 Future benefits of Flutter: Web apps and desktop apps


As of this writing, the Flutter team has officially announced Flutter for the web (also
known as Hummingbird). This project is extremely exciting. When it’s stable, Flutter
will be the first framework that is truly “write once, deploy everywhere.” Flutter is work-
ing on the functionality to deploy applications not only to iOS and Android, but also
ChromeOS, browsers, macOS, Windows desktop apps, and Fuchsia.
As of Google I/O 2019, Flutter web is in technical preview. Right now, you can
experiment with it and make web apps. That being said, I will not be talking about
Flutter web in this book. There are two reasons for this:
 As I mentioned, the project is currently in the technical preview stage. That
means everything you learn about it is likely to change.
 More important, the goal of Flutter web is that it “just works.” So, in theory, if
you learn everything in this book, once Flutter web becomes stable, you’ll
already know everything you need to write a web app with Flutter.

1.9 A brief intro to how Flutter works


At a high level, Flutter is a reactive, declarative, and composable view-layer library,
much like ReactJS on the web (but more like React mixed with the browser, because
Flutter is a complete rendering engine as well). In a nutshell, you build a mobile UI by
composing together a bunch of smaller components called widgets. Everything is a
widget, and widgets are just Dart classes that know how to describe their view. Struc-
ture is defined with widgets, styles are defined with widgets, and so are animations and
anything else you can think of that makes up a UI.2

WARNING “Everything is a widget” is a potentially misleading statement that


you’ll see everywhere on the internet, including in the official documenta-
tion. This doesn’t mean there aren’t other objects in Flutter. Rather, it means
that every piece of your app is a widget. Styles, animations, lists, text, buttons,
and even pages are widgets. For example, there isn’t an object called “App”
that defines the root of your application. The root of your application can
technically be any widget. To be sure, there are other objects in the Flutter
SDK (such as elements), which we’ll discuss later.

2
A brief intro to widgets from the docs: http://mng.bz/DNxa.
A brief intro to how Flutter works 13

Suppose you’re building a shopping cart app. The app is pretty standard: it’ll list prod-
ucts, which you can add to a cart via Add and Remove buttons. Well, the list, the prod-
ucts, the buttons, the images, and everything else are widgets. Figure 1.3 shows how
some of these widgets would be coded. Other than widgets, the only classes you’re
likely to write are your own logic-specific classes, which aren’t related to Flutter.

build(BuildContext context) {

return Column(
AWESOME SHOES

(image) //...
qty: 1
Image(),

Text("BETTER SHOES"),
BETTER SHOES
//...
(image) qty: 1
IconButton(

icon: Icon(Icons.chevron_left),

),

Text("Page $page_num"),

Page 1 //...

); // column

Figure 1.3 Everything is a widget.

Everything is widgets inside widgets inside widgets. Some widgets have state: for exam-
ple, the quantity widgets that keep track of how many of each item to add to the cart.
When a widget’s state changes, the framework is alerted, and it compares the new wid-
get tree description to the previous description and changes only the widgets that are
necessary. Looking at our cart example, when a user presses the + button on the quan-
tity widget, it updates the internal state, which tells Flutter to repaint all widgets that
depend on that state (in this case, the text widget). Figure 1.4 shows a wire frame of
what the widgets might look like before and after pressing the “+” IconButton.

BETTER SHOES onPressed() { BETTER SHOES onPressed() {

(image) qty:1 // increase quantity (image) qty:2 // increase quantity

} }

Figure 1.4 setState updates the displayed quantity.


14 CHAPTER 1 Meet Flutter

Those two ideas (widgets and updating state) are truly the core of what we care about
as developers. For the remainder of this chapter, I want to break down, in depth,
what’s really happening.

1.9.1 Everything is a widget


This is a core idea in Flutter. Everything is a widget. Again, this doesn’t mean that
there aren’t other object types in Flutter—there are. Later in this book, I explore
these other objects in depth, but as a developer you’ll rarely care about anything other
than widgets. The point is that there aren’t models and view models or any other spe-
cific class type in Flutter.
A widget can define any aspect of an application’s view. Some widgets, such as Row,
define aspects of the layout. Some are less abstract and define structural elements, like
Button and TextField. Even the root of your application is a widget.
Using the shopping cart example again, figure 1.5 shows how you might code
some of the layout widgets, while figure 1.6 shows some structural widgets. To be sure,
though, there are a lot more widgets than we can see, because they define layout,
styles, animations, and so on.
For context, these are some of the most common widgets:
 Layout—Row, Column, Scaffold, Stack
 Structures—Button, Toast, MenuDrawer
 Styles—TextStyle, Color
 Animations—FadeInPhoto, transformations
 Positioning and alignment—Center, Padding

build(BuildContext context) {
return Column(
AWESOME SHOES
//...
(image) qty: 1
Row(),
Padding(),

BETTER SHOES //...

(image) qty: 1 Row(


children: [
IconButton(),
//...
],

Page 1 ), // row
); // column
}

Figure 1.5 Examples of common layout widgets


Exploring the Variety of Random
Documents with Different Content
Sylvia told him, made it apparent to him that Madame Claudet was a
most extravagant woman.
“We are out every night somewhere,” the girl said. “And madame will
never allow us to pay a farthing. She must be very rich, for she’s
ordered eight new frocks from Lucille’s.”
“She has no friends in London, has she?” Falconer asked casually.
“She didn’t have any when she arrived, but, of course, she now
knows one or two people to whom we’ve introduced her.”
On the following day another curious telegram came through the
wireless station at Witham. Dispatched from Marseilles, it had been
sent across by wireless from Paris, and was addressed to Mildmay. It
was in plain language, and read: “Urgent that Marguerite should
come over. The change would do her good.—Jules.”
This puzzled Geoffrey more than ever. Why was madame wanted
urgently at Marseilles, and what hidden meaning was contained in
the declaration that the change would do her good? He was very
anxious to ascertain if she ever met the mysterious Mildmay, and for
that purpose he went to London one evening and again saw his
friend the liftman.
No lady had visited Mr. Mildmay to his knowledge. She certainly
might have called when he was off duty.
Hence Falconer determined to watch again, and after the lapse of
several weary evenings, he one night followed Mildmay to the Savoy,
where, just before supper-time, he took a seat in the lounge and idly
lit a cigarette.
Ten minutes later Geoffrey saw standing at the head of the short
flight of stairs the familiar figure of Madame Claudet, wearing a
gorgeous theatre wrap. Her quick eye recognised Mildmay; therefore
she went to take off her wrap, and a few moments later joined him.
From a distance Falconer watched them closely. Mildmay’s greeting
appeared the reverse of cordial, for on his face was an angry,
morose expression. After a brief conversation, they passed into the
supper-room, where, in order to escape recognition, Geoffrey was
forced to leave them. But he had established the fact of their secret
friendship.
Next evening when he went to Upper Brook Street he found Sylvia
alone, her mother having gone to the theatre with madame.
“Isn’t it a shame!” she remarked. “Madame Claudet has to go to
Paris the day after to-morrow—on some of her horrid banking
business again. Mother has introduced her to her bank in Pall Mall,
so that she has an account in London, therefore these journeys will
be avoided in future.”
Geoffrey, who had not allowed either Mrs. Beverley or her daughter
to suspect his doubt concerning the handsome widow, agreed, and
expressed a hope that the lady would soon return.
Next day, having to be at Marconi House, he snatched off a few
hours in the afternoon, and succeeded in watching madame leave
Upper Brook Street alone, and following her to Ryder Street, where
she called upon Mildmay. It was very apparent, by the timid way she
slipped into the doorway of the chambers, that she feared being
watched. Why?
She remained there for about half an hour, when, emerging, the
liftman hailed a taxi for her and she drove to Upper Brook Street.
Geoffrey was perplexed why the mysterious Jules in Marseilles
should be so concerned regarding madame’s health. Hence he
determined to watch her movements closely until she should leave
Victoria. That night he did not return to Warley, but slept at his club,
and at ten o’clock next morning idled unseen at the corner of Upper
Brook Street, in case she should come forth. He had ascertained that
she was leaving Victoria at midday.
At about half-past ten madame came out alone, carrying her
handsome gold-mounted handbag, and in Grosvenor Square she
hailed a taxi, in which she drove to a bank in Pall Mall, in order, no
doubt, to obtain money for her journey.
She remained within about ten minutes or so, then, re-entering the
taxi, she drove back to her hostess’s house.
A quarter of an hour later Geoffrey called to wish the gay widow au
revoir, and Mrs. Beverley invited him to stay to luncheon. At about
half-past eleven madame left for Victoria, her hostess going in the
car to the station to see her off. Hence Sylvia and her lover were left
together.
Geoffrey Falconer had become disappointed and ill at ease, for the
mystery concerning the widow still remained unsolved.
Mrs. Beverley returned, and they had luncheon together, the young
wireless engineer remaining all the afternoon.
Just as they were seated at tea, Shaw, the footman, brought a card
to his mistress, who glanced at it, and said:
“Oh! It’s Mr. Elton! I wonder why he wants to see me? Ask him in
here.”
The man bowed, and a few moments later a tall, clean-shaven
business man was ushered in. In a second it was plain that he was
considerably perturbed.
“Mrs. Beverley,” he said, glancing at Sylvia and Geoffrey, “I am very
sorry to disturb you with a most unpleasant matter. May I see you
alone?”
“Unpleasant matter!” gasped the South American woman. “What do
you mean? Whatever you have to say can be said right here.”
“You have a Madame Claudet staying with you. You introduced her
to me, and she opened a small account at our bank,” he said. “Well
—I may as well tell you that I have the police outside, and I am here
to give her into custody!”
Mrs. Beverley stood open-mouthed.
“Custody!” she gasped. “For what?”
“She called at the bank this morning, and changed seventy-four
thousand five-hundred francs in French notes for English notes.
These were, at noon, sent along to the head office in Lombard
Street, where they have been found to be marvellously clever
forgeries!”
“Impossible!” declared Mrs. Beverley, utterly staggered.
“Alas! it is only too true. The bank has lost nearly three thousand
pounds.”
Then Mrs. Beverley, having explained how her late guest had left for
Paris that morning, refused to believe that she could be guilty of any
such fraud.
Here Geoffrey interrupted, and related how he had unconsciously
endeavoured to pass a forged note at Tours, and he recalled to her
mind the incident at the jewellers in Dinard. Both those
circumstances pointed to the fact that the woman had taken from
the purses of both Geoffrey and her hostess real notes, substituting
false ones, with the idea of watching whether they would be passed
or not.
“I would like a word with the police,” Geoffrey added, and with the
bank manager he left the ladies to recover from their sudden shock.
In the library he saw the detective-inspector, and briefly related the
mysterious messages received by Mr. Mildmay, and the circumstance
of the electric motor and the locked room.
Within half an hour a priority telegram had been sent by wireless by
Scotland Yard to the commissary of police at the Gare du Nord, in
Paris, to arrest madame on her arrival, while a visit to Mr. Mildmay’s
chambers revealed in the locked room a perfect plant for the
reproduction of French and Spanish bank notes of various
denominations, the most scientific and complete ever found in the
possession of bank-note forgers.
Two hours later, when Mildmay returned, he found himself suddenly
in the hands of the police, and both he and madame—who was not
a widow at all, but his wife who had been distributing forged French
and Spanish notes all over Europe, and reaping a rich harvest—later
on received exemplary sentences at the Old Bailey.
CHAPTER VI
THE CLOVEN HOOF

“It should be quite a pleasant trip for you, Falconer,” remarked the
little, middle-aged, well-dressed man who was one of his superiors,
as they sat together in a room in the Engineering Section at Marconi
House on a bright October afternoon. “The plant went out from the
works at Chelmsford three months ago, and we have been advised
that it has all arrived in Hungary, or I suppose they call it Czecho-
Slovakia now, and it is lying at the station at Arad.”
“I will do my best,” replied Geoffrey, greatly delighted at the
instructions he had just been given, namely, to proceed to Hungary
to erect two complete one-and-a-half kilowatt stations for
continuous-wave telegraphy and telephony. “I have never been in
Hungary, and it will, no doubt, be interesting.”
“It will. I’d dearly like to go with you,” laughed Mr. Millard, one of the
best-known of wireless engineers. “The sets have been purchased by
the Baron de Pelzel, on behalf of the new Government of Czecho-
Slovakia, and one of the conditions of the contract provides that we
should send out an engineer to erect the stations.”
“Will anyone go with me?” asked Geoffrey.
“No. There is, I think, no need. I myself looked through the
instruments before they were packed. All is in order. You can employ
local labour. There are surely some quite good electricians in
Hungary. The first station is to be erected somewhere near Arad—
wherever that may be—and the other in some other part of Hungary.
We thought you would like an opportunity to go abroad.”
Geoffrey thanked the chief of his department, and then, after
receiving a number of other instructions, he went down in the lift
and out into the busy Strand.
Half an hour later he was at Mrs. Beverley’s.
“Hulloa, Geoff!” cried Sylvia as he entered the room. “Where have
you sprung from? I thought of you down at Chelmsford with your
uncomfortable old telephones on your ears, turning little handles
very slowly, and listening! Oh, Geoff, you look so funny sometimes
when you listen! You look as if your whole life depended upon it,”
added the girl chaffingly.
“And so it does, dear. At least my bread-and-cheese depends upon
it.”
“Why, the other day Colonel Maybury, of the Air Ministry, told me
that your improved amplifier will probably bring you a comfortable
fortune in royalties!”
The keen, smooth-haired young fellow shrugged his shoulders, and
replied:
“I only hope it will. We wireless men are never optimists, you know.
We always look for failure first. Success surprises us, and bucks us
up. When one is dealing with a science which is in its infancy one
must first look for failure.”
“My dear Geoffrey, as I’ve said before, you are so horribly
philosophic about things,” she declared with a laugh.
At that moment her mother entered, and invited Geoffrey to stay to
dinner en famille. The ladies, however, put on dance frocks, for they
were due at Lady Waterden’s at nine o’clock. So about that hour,
after Falconer had told them of his impending journey to Hungary,
he saw them into the car and then walked to the corner of
Grosvenor Square, where he took a taxi to Liverpool Street and
caught the train to Warley.
At the Works at Chelmsford next day he was handed a copy of a
letter from the Baron de Pelzel, who had purchased the installations
on behalf of the Government of Czecho-Slovakia. It was a private
letter dated from the Schloss Nyék, in Transylvania, recalling the fact
that all the plant had already arrived at Arad, and asking the Marconi
Company to send their engineer to Budapest as soon as possible,
where he would meet him at the Ritz Hotel and consult with him.
A week later Falconer left London—after an affectionate farewell to
Sylvia—and travelling by the Orient express by way of Paris, Wels,
and Vienna, duly arrived at the Hungarian capital. The moment he
entered the taxi to drive to the Ritz—that hôtel de luxe overlooking
the Danube—a great change was apparent in what was once the
gayest city in Europe. The war had brought disaster upon the
unfortunate Hungarians, who, owing to the terribly low rate of
exchange, and the difficulty of food imports, were now half-starving.
As in the late afternoon Geoffrey went from the station along the
wide handsome street half the shops were closed, and the passers-
by were mostly thin-faced, ill-dressed and shabby.
At the hotel a brave show of luxury was made, and naturally the
charges were high—in Austrian coinage. The price asked for a room
with bathroom adjoining was enormous, but when he calculated it in
English money at the current rate of exchange it was about two
shillings and sixpence a night!
He inquired at the bureau if the Baron de Pelzel had arrived, and
received an affirmative reply. The Baron and his niece had gone out
motoring to Szajol, a place on the River Tisza, and would return
about six. He had left that message for Geoffrey.
About half-past six a waiter came to Falconer’s room asking him to
go along to the Baron’s sitting-room, which was on the same floor.
This he did, and there met a tall, well-built, very elegant, brown-
bearded man of about forty, with a round, merry, fresh-
complexioned face and a pair of dark, humorous eyes.
He welcomed Falconer in very good English and at once introduced
him to his niece, Françoise Biringer, a tall, rather slim, dark-eyed girl,
very smartly attired, who spoke to him in French. Apparently she
knew but very little English.
Then when the girl had gone to dress for dinner, the two men sat
down and discussed the business in hand.
The Baron seemed an extremely affable and cultured man, as so
many Hungarians are. He lived mostly in Paris, he explained, but
since the war he had assisted his Government in various matters.
“I hope you will have an enjoyable time, Mr. Falconer,” he went on.
“When I was at Marconi House they told me they would send out an
expert engineer to fit both stations and get them going. How far do
you think I can speak over the set they have sent me?”
“Speech should carry from seven hundred to nine hundred miles—
perhaps more under favourable conditions, but Morse signals will
carry very much further.”
The Baron seemed highly satisfied.
“You see, my Government is greatly interested in certain mining
enterprises, and it is my plan to set up two wireless stations on
either side of Hungary, so that we can conduct rapid business from
one zone of operation to the other, and also with Budapest when we
so desire. But,” he added, “it is annoying that the plant should have
been sent to Arad. There must have been some mistake. I went to
Arad last week and saw the railway people there. It has already
been passed on to its proper destination. But I do not expect it will
arrive for a week or even ten days, so during that time I hope you
will honour me by being my guest here, as well as during the time
you are engaged in fitting the installation.”
“I shall require assistance,” Geoffrey said. “Do you happen to know
of, say, two good electricians whom I could engage as assistants?”
“I will inquire,” replied the Baron. “No doubt we can find two good
men who, during the war, were engaged in radio-telegraphy.”
Afterwards Geoffrey, well-impressed by the genial Baron, returned to
dress for dinner, and later on took a perfectly cooked meal with his
elegant and courteous host and his niece. The young man found the
pretty Françoise extremely interesting. They discussed many things
at table, new books, new plays, and, of course, the terrible havoc of
the war.
The Baron was pro-British in all his remarks. He deplored the
ridiculous weakness of the poor old doddering Emperor Franz-Josef,
who, as every one knew, was beneath the thumb of a wily
adventuress, and with vehemence declared: “We were always
Britain’s friends. We should never have opposed her. Look at our
poor Hungary now! Only ruin and starvation! Until we can recover
ourselves we shall be at the mercy of any of the petty Powers who
make themselves so conspicuous and obnoxious at the eternal
pourparlers presided over by your Premier. We want peace, Mr.
Falconer,” cried the Baron furiously. “Peace, and with it renewed
prosperity. But there!” he added. “Pardon me! I apologise. Françoise
knows that this constant casting of dust in the eyes of our poor
starving people goads me to the point of fury.”
Even though Hungary was in such evil case, and half the population
were starving, yet at that hotel people—many of them war-profiteers
as in London—dined expensively, danced, and thoroughly enjoyed
themselves. To them it mattered not how freely the bones of the
poor rattled, or how many children died daily of sheer starvation.
They had money—and with it they bought merriment and “life.”
After dinner the Baron’s car took them down the Nagy-Korut—the
Great Boulevard—to the Folies Caprice, where they spent the
evening at an excellent variety performance.
That night when Geoffrey retired to his room he was fully satisfied
with the warm reception and generosity of the Baron, and charmed
with the chic and verve of his pretty niece Françoise, who seemed to
have spent most of her life in Paris, where her father had an
apartment close to the Étoile.
Next day the Baron invited the young radio-engineer to have a run in
the Mercedes, and the rather morose Frenchman, Lebon, who drove,
took them out to Tepla, a very beautiful spot with warm springs that
have been visited for centuries by the Hungarian nobility. They
lunched at the Sina-haz, one of the many excellent hotels, and ran
back through Trencsen, where they pulled up to find the “Lovers’
Well.”
After an inquiry from the Baron, who alone spoke the Hungarian
tongue, they discovered it just outside the village, within the
confines of the ruin of a Roman castle—a well dug in the rock.
The Baron and the peasant who conducted them to it had a short
chat. Then Françoise’s uncle turned to them, and explained in
French:
“A most curious story this good man tells. It seems that centuries
ago a young Turk of high rank and family offered a large ransom for
his bride, who was in captivity in this castle. But the lord of the
castle, Stephen Zapolya, demanded as the price of her release that
her lover should dig a well through the rock. After seven years’ hard
work the well was completed, and the spring is to this day called the
‘Lovers’ Well.’”
With Françoise, Geoffrey peered down into the pitch darkness, and
saw that it was really cut in the rock. As they did so, their hands
came into contact. Indeed, she grasped his instinctively as they
stood together at the edge of the deep well.
Then she withdrew her hand quickly with a word of apology, and ten
minutes later they were in the car back upon the broad highway
which led to Budapest.
The autumn days passed very pleasantly. Living so much in Paris, as
he had done of late, the Baron, apparently, had but few friends in
Budapest. He, however, had much business to attend to in the
daytime on behalf of his Government, hence Falconer and the
Baron’s pretty niece were thrown constantly into each other’s
society.
She was a smart girl, full of a keen sense of humour, and possessing
all the verve of the true Parisienne. She knew Budapest, of course,
and acted as Geoffrey’s guide in the city, but her heart was always in
Paris. She regarded the Hungarians as an uncouth race.
Her mother had been French, she told him one day. She had, alas!
died two years ago. But she had induced her father to take the flat
in Paris rather than remain in the wilds of Hungary.
More than once Falconer wrote to Sylvia telling her of the society
junketings in Budapest, while the city starved. Each night they dined
expensively and went either to the opera, or to the Vigszinhas to see
comedy; to the Fortress, or the People’s Theatre. They also went to
the Arena in the Town Park, the performances at which were quite
as good as in pre-war days.
One evening as Geoffrey sat in the palm court of the Ritz with
Françoise, she exclaimed suddenly in French: “I think we go to-
morrow or the next day. My uncle was with Count Halmi this
afternoon, and they were speaking of it. All the wireless apparatus
has arrived at Zenta.”
“Zenta? Where is that?” asked Geoffrey, removing his cigarette, for
the pair were alone together in a corner of the lounge. Françoise
looked very pretty in a jade-coloured dance frock, for a dance to
weird Tsigane music was to commence in the great ballroom in half
an hour.
“Zenta! Why, don’t you know? Has not the Baron told you? It is his
estate right away on the other side of Hungary—near the Russian
frontier. I confess that it is out of the world, and I do hope you will
not be bored to death there!”
“No doubt I shall not; I have my work to do,” laughed the well-set-
up young Englishman, for he was really having a most enjoyable
time.
Hence he was not surprised when two days later his host, the Baron,
departed for the Schloss Zenta.
In the express between Budapest and Debrechen, on the line which
leads out to the Polish frontier, the Baron, lolling lazily in the corner
of the first-class compartment, remarked in English:
“I hope, Mr. Falconer, you have not been disappointed with
Budapest. Unfortunately I have had so many official affairs to attend
to. We shall be at home at Zenta to-night. I fear it may be very dull
for you, as it is far away up in the mountains. I only yesterday
received word that all your apparatus has arrived there.”
“What height is it?” Geoffrey asked, as he was concerned with the
height of his aerial wires.
“I hardly know,” the Baron laughed. “I’ve never tested it with an
aneroid. No doubt you will. It is high, and that is why I thought it
would suit you, because I’ve always understood that aerial wires for
wireless are best on a hill.”
“Certainly they are,” said Falconer, gazing out upon the beautiful
panorama of stream and mountain through which they were
passing. They were entering the most remote, but most beautiful,
district in all Hungary, that which lies between the High Tatra—a
lovely mountain district known so little to English travellers, save
those familiar with the Carpathians—and the Roumanian frontier.
At evening they arrived at a small, picturesque town called Nagy-
Károly, the capital of the Szatmas country, nestling between the
mountains, and at once a powerful car took them for about thirty
miles up higher and higher into a wild remote district, the very name
of which was unknown to Geoffrey. Presently, just as the night was
drawing in, the pretty Françoise pointed to a high-up château
perched on the edge of a steep rocky precipice, and said:
“Look! There is Zenta—at last!”
It looked, as indeed it was, one of those ancient strongholds of the
Hungarian barons who had for ages resisted the repeated invasions
of the Turks.
Later, when they arrived and the Baron showed him round before
dressing for dinner, he found that it was a splendid old fortress, full
of rare antiques and breathing an air of days long gone by, while at
the same time it was also the comfortable home of a very wealthy
man.
That night as they sat at dinner in the long panelled dining-room
adorned with many heads of stags and bears, trophies of the chase,
the Baron raised his glass of Imperial Tokay and welcomed his guest
beneath his roof.
“Here,” he said, “you have a very historic old place which you are
going to fit with the latest invention of wireless—the radio-
telephone. A strange combination, is it not? All your boxes have
arrived, and they are in the back courtyard. I am sorry that I was
not able to arrange for expert assistance for you, Mr. Falconer, but I
have two very good electricians arriving to-morrow. My agent in
Vienna is sending them.”
And at the same moment Karl, the Magyar servant, in his brown
velvet dress and big buttons of silver filigree, helped him to a
succulent dish of paprika lamb, which followed the halaszle, that
famous fish soup which is served nightly in all the wealthier houses
in Hungary.
“Have the engines and all the other plant arrived?” Geoffrey
inquired.
“Everything. Twenty-eight packages in all,” answered the brown-
bearded man, while Françoise, with her bare elbows on the table,
glanced across at the young Marconi engineer, and remarked in
French:
“I suppose you will be horribly busy now—eh, M’sieur Falconer?”
“Yes, mademoiselle,” he replied. “I have lost more than a fortnight
already. But it has, I confess, been most enjoyable.” Then turning to
the Baron, he asked:
“Have you engaged any operators to work the set?”
The question, put so suddenly to De Pelzel, nonplussed him. He was
compelled to hesitate for a few seconds—a fact which did not escape
the alert Geoffrey.
“Oh! how very foolish of me!” the Baron exclaimed in his suave, easy
manner. “I have been so terribly busy of late, and also rectifying the
blunder of sending the boxes to Arad, that I quite forgot the
necessity of a staff to work the installation when it is complete. I will
at once see about getting some ex-radio military men from Vienna.”
For half an hour after dinner a gipsy orchestra, four swarthy-faced
men in brown velvet, with dark, piercing eyes, and lank black hair,
gave some wonderful music with their violins. Then, when near
midnight, the man-servant Karl showed Geoffrey to his room—a big,
gloomy, dispiriting place, lit only by two candles in ancient silver
holders.
When Karl had shut the door, Geoffrey instantly experienced a
curious feeling of impending evil. Why, he knew not. He was there
upon business for his company in that remote, out-of-the-world
place, and his host, the Baron, was most kind and affable, while his
niece was quite charming. Yet somehow as he lay awake the greater
part of the night he became consumed by a strange apprehension.
At the Ritz, in Budapest, and also in the train, he had noticed on
several occasions a curious exchange of glances between uncle and
niece—or was it only his fancy?
Was anything amiss? He lay listening to the owls hooting in the great
forest which surrounded the castle on three sides, and reflected
deeply. Françoise, he remembered, had during the past few days
questioned him very cleverly, yet very closely, concerning himself
and his family. Could there be any motive in that? In the silent hours
of that night he became haunted by dark suspicions, but next
morning when he awoke refreshed and went out in the autumn
sunshine along the terrace, which gave a magnificent view of the
great Hungarian plain for many miles, all his apprehensions were
quickly dispelled.
Inwardly he laughed heartily at his own misgivings.
At eleven o’clock he drove with the Baron about three miles into the
forest to a large high-up clearing—the spot which De Pelzel
suggested should be the site of the new station. Indeed, two new
log huts were already built for the transmitting and receiving gear,
with a remote control to the generator plant.
Geoffrey, looking round upon the dense firs which screened them on
every side save to the east, was surprised that such a site should
have been chosen. But next second he recollected that the Baron
knew nothing of wireless requirements.
“To tell you the truth,” Geoffrey said frankly, “I do not favour this
spot at all. Results would be far better if we fitted the station
somewhere else, for instance, near the terrace at the Schloss.”
“I quite imagine it, Mr. Falconer,” replied the eminently polite Baron.
“But, unfortunately, my Government is desirous of possessing a
confidential means of conversation between the two mining zones,
and I have granted them permission to establish it here on my
estate.”
“And the corresponding station?” asked Geoffrey.
“I will explain the situation of that later—when we have decided
upon this.”
Falconer was disappointed. He saw that the aerial would be far too
directional for the best results.
“This evening,” the Baron went on, “I hope your two assistants will
be here. This car will then be at your disposal to take you backwards
and forwards from the castle.”
To protest against such a site was, apparently, useless. All that
Geoffrey could do was to warn the Baron that the results were not
likely to be too good.
“Well,” he laughed, “I’ve bought the plant, and if I choose to erect it
anywhere, I suppose I am at liberty to do so. You, Mr. Falconer, with
your expert knowledge, will, no doubt, be able to make it work all
right!” he said good-humouredly.
“Well—I’ll try,” Geoffrey replied, and on his return to Zenta he sat
down and wrote a long letter to Sylvia, telling her his whereabouts,
and how the material had been addressed to Arad wrongly, of his life
with the Baron, and of the rather unsatisfactory site that had been
chosen.
He wrote four closely-filled pages, and having finished took it to one
of the small rooms where Françoise was sitting reading a French
novel.
“The post goes out every night at seven o’clock,” she said. “If you
will put it in the rack by the front entrance Karl will see that it is put
with the others this evening. Ludwig goes in the light car, and takes
the letters into Deva. They go by road to Nagy-Károly to-morrow
morning, and on by rail.”
Next day two shrewd-looking Austrian engineers presented
themselves as Geoffrey’s assistants. Both spoke French, and when
Falconer questioned them he discovered that the elder of the pair
knew a good deal about radio-telephony.
They therefore set to work to open the huge boxes of apparatus
which had been over three months on their way from Chelmsford.
Each was marked, and they, of course, only unpacked one complete
set, together with the aerial masts and wires. This work took three
days, after which the whole of the plant was carried up by horses
through the forest to the clearing which had been made near the top
of the mountain.
Day by day Geoffrey was out there with his two assistants, first
erecting the aerial—one of the newest type—and then making an
“earth” by sinking three-foot copper plates edgewise in the form of a
ring, and connecting all of them to a central point. Each evening he
was back at the castle, where he spent many pleasant hours with
the Baron and his charming niece. The latter, indeed, took him on
several occasions to see the most delightful pieces of mountain
scenery while the Baron, hearty and full of bonhomie, was keenly
interested to watch Geoffrey at work fitting the complicated-looking
apparatus.
Yet, curiously enough, Geoffrey’s strange feeling of apprehension
had not passed. He could not rid himself of that creepy feeling which
had stolen over him on the night of his arrival at the castle of Zenta.
Why, he could not tell.
He was surprised that he had no answer to his three letters to Sylvia
since he had been there, but he recollected that Mrs. Beverley had
spoken of going to Paris for a fortnight or so, to do some shopping,
hence it was quite possible that mother and daughter had left
London.
It struck him, too, as somewhat strange that the Baron’s pretty niece
should evince so much inquisitiveness concerning his affairs. When
they were together she frequently turned the conversation very
cleverly, and questioned him about his friends in England.
“I’m terribly bored here,” she declared in French one night after
dinner, as she sat with a cigarette between her fingers and yawned.
“At last I’ve persuaded my uncle to let me go back to Paris. I shall
return very soon.”
“Will you?” asked Falconer. “I expect to be here quite another
fortnight before we can get going. Then I have to erect the other
station. Have you any idea where that is to be?”
“No,” she said. “Uncle has never told me. But, no doubt, it will be a
long way from here.”
The secrecy concerning the position of the corresponding station
also puzzled the young fellow. The Baron had, however, promised to
let him know in due course, so he continued his work out in the
forest, and gradually he assembled the engine, generator, and all the
apparatus necessary for radio-telegraphy and telephony.
One afternoon he returned to the castle unusually early, and was
surprised to discover the Baron—who had not seen him—emerge
from his bedroom and slip down the stairs. On examining his suit-
case a few moments later he saw that the lock had been tampered
with, and all his papers had been overhauled!
What object, he wondered, could his genial host have in prying into
his private affairs?
By day the two Austrians working under his direction were ever
diligent—both being excellent fellows, and very careful and precise in
their work, which is most necessary in setting up a wireless station.
At night they remained at the castle in quarters which the Baron had
provided.
So far from everywhere was the castle that the Baron seldom had
visitors except on two occasions, when two gentlemen, one a short,
stout, thick-set man, probably an Austrian, and the other a middle-
aged Russian who seemed something of a cosmopolitan, arrived,
and after spending the night, drove away again.
From Françoise he understood that the Austrian, whose name was
Koblitz, was a Government undersecretary, and the Russian’s name
was Isaakoff, and that their visits were upon official matters
concerning Czecho-Slovakia.
At last, one day when Doctor Koblitz had unexpectedly arrived alone,
the new wireless station in the forest was completed, and Geoffrey
thoroughly tested the reception side, which he found gave highly
satisfactory results, considering the screening from the trees. Both
the Baron and Doctor Koblitz, together with Françoise, took the
telephones and listened to the signals from Elvise, Rome, Warsaw,
Carnarvon, Arlington, Lafayette, Lyons, and other of the “long-wave”
stations. Indeed, during the whole afternoon Geoffrey entertained
them by tuning-in messages and copying them from dots and
dashes of the Morse code.
Both the Baron and Koblitz expressed their delight; therefore that
evening Geoffrey ventured to ask where the second station was to
be erected, for quite ten days before all the remaining cases had
been despatched to a destination of which he had been kept in
ignorance.
“My Government have not yet decided,” was his reply. “The boxes
have been sent to Versec, close to the Serbian frontier. No doubt to-
morrow or next day we shall hear what is decided. You said this
afternoon that you have finished, and that all is in order to transmit
—as well as to receive?”
“Yes,” Geoffrey replied, “all is ready. I have only now to put up the
corresponding station.”
“Could you, for instance, send off a message for me to-morrow—say
at noon?”
“Certainly,” said Falconer. “We are ready to run and give a test
whenever you like.”
“Excellent. Then we will go over in the car to-morrow and send out
the test message—eh, Monsieur Koblitz?” was the genial, brown-
bearded man’s reply.
That night Geoffrey failed to sleep. Five weeks had passed since he
left London, and though he had written to Sylvia several times, he
had received no word of reply. If she had been in Paris, she was
surely at Upper Brook Street again!
He was ignorant of the significant fact that each letter he had left for
Ludwig to post had been taken by Françoise and handed to her
uncle, who had opened it and read it in conjunction with Karl, the
faithful man-servant. Afterwards each letter had been burned. This
had been repeated each time Geoffrey had written a letter, either to
Marconi House, to his father at Warley, or to any other person.
On Sylvia’s part she was still writing to the Ritz, at Budapest, whence
she had had a letter from her lover, and they were retaining the
letters expecting the young English engineer to return, as the Baron,
unknown to Geoffrey, had promised.
Next morning broke chill and misty over the Carpathians, and at
half-past eleven the Baron, accompanied by Falconer, Françoise, and
Koblitz, drove to the newly completed wireless station.
Inside the transmission hut as they stood together, the Baron took
out a slip of thin paper which he carefully unfolded and handed to
his companion, saying:
“The call-signal will not be found in the official book.” Then added:
“As you see, the message is seven-figure code.”
Geoffrey looked and saw that the call-letters written upon the slip of
paper were C.H.X.R., followed by a jumble of figures interspersed
with letters of the alphabet.
The initial letter of the call showed that the station wanted was
either in Spain, Portugal, Morocco, or Roumania. No doubt it was in
the latter country.
“The call-signal allotted to this station is the letters O.S.R.U.,” the
Baron said, after referring to his pocket-book.
So the young radio-engineer at once sat down to the key and tapped
out the usual preliminary call, followed by his own call and the call of
the unknown station he wanted.
“Get them first by telegraphy, and then I will telephone to them,”
urged the Baron excitedly.
Within ten minutes Geoffrey obtained a response, and after sending
the code message by telegraph, he switched on the telephone
transmitter, and handed the microphone to the Baron.
“Hullo! Hullo! Hullo! Petresco? Petresco?” he called, holding the
transmitter close to his lips. Then in English he went on: “Can you
hear me? Is speech all right? This is a test to you. Please tell me
whether you have heard me distinctly. Hullo! Petresco? Hullo!
Petresco? This is O.S.R.U. calling—calling C.H.X.R.”
And he handed the microphone to Geoffrey, who at once repeated
the query, and concluded it with the words always used in wireless
telephony: “O.S.R.U., changing over.”
In a few moments there came a clear voice evidently at a
considerable distance, saying:
“Hullo! O.S.R.U.? Hullo! Your signals are quite O.K. Your modulation
quite good. Congratulations!”
He handed the head-’phones to the Baron, who, with great
satisfaction, heard the speech repeated. They were certainly in
touch with the mysterious station in Roumania.
While the test was in progress Françoise stood in the narrow little
room watching intently.
“Really marvellous!” Mademoiselle declared when she herself put on
the telephones and heard the reply again repeated in a clear, rather
musical voice.
Then, after another ten minutes, the Baron asked Falconer to switch
off the generator and close down, as they would be late for
luncheon.
“It does you very great credit,” declared the owner of the great
estate of Zenta. “I never dreamed that we should be in such
complete touch so quickly.” And the man Koblitz also tendered his
congratulations upon the achievement.
Later in the afternoon Mademoiselle Françoise left for Paris, and
Geoffrey shook her hand as she entered the car. After dinner
Falconer smoked with the Baron and his friend until about eleven
o’clock, when he put down his cigar and wished them both good-
night. It had become apparent that the pair wished to be rid of him
for some reason. Therefore he retired.
Back in his great, gloomy bedroom he stood for some time at the
window, gazing out upon the gorgeous scene of moonlit mountain
and silent Carpathian forest. The attitude of the two men during that
evening had become suspicious—the more so because the Baron
had so constantly evaded his question as to the site of the second
wireless station, and also the identity of the mystery station,
“C.H.X.R.” Who, too, was Petresco? It was apparently a Roumanian
name. Once again a strange intuition crept over him—a premonition
of impending evil.
A quarter of an hour later he removed his evening shoes and crept
back again down the great oak staircase to the door of the room
wherein the two men were in consultation.
Bending he could hear their voices speaking low and confidentially.
But they were speaking in Hungarian, hence he could not
understand a single word. Probably it was only politics they were
discussing; therefore, after waiting ten minutes, all the time in fear
of the approach of Karl, he was about to return to his room when, of
a sudden, he heard a few words in French.
Koblitz was speaking.
“Yes, I quite agree,” he said. “Your plan is excellent. The wireless
station must remain a complete secret. This young fellow’s lips must
be closed. The two men we have here are both good wireless men,
and are affiliated to our cause. Hence they can be trusted
completely. Falconer we cannot trust—even if we attempted to bribe
him, for he is an Englishman and would accept nothing.”
“I am glad you agree, mon cher,” the Baron replied. “At the wireless
station to-morrow he will accept a drink from my flask—and then—
well, the forest will an hour later hold its secret,” he remarked
meaningly.
Geoffrey held his breath. Could it be possible that their plan was to
poison him, and bury him in the forest, now that he had completed
his work?
It was quite apparent that the station he had erected was a secret
one, established for some illicit purpose.
He listened again, but Koblitz was only congratulating his friend
upon the success of what he termed “the great scheme.”
Silently Geoffrey crept back up to his room. His mind was made up.
By his natural intuition of impending peril he had been forewarned.
Hence putting on a pair of strong walking boots, he assumed his
overcoat and let himself out of the great rambling place by a door he
knew. In the moonlight he ascended the steep winding path which
led to the wireless huts, and on arrival there, unlocked the house in
which the transmission panel was erected. Then, switching on the
light, he took up a hammer and deliberately smashed every one of
the big glass valves.
Not content with that, he also smashed every spare valve, and then
destroyed the insulation upon two transformers of the receiving set,
thus putting the whole station out of action.
Afterwards he relocked the door and made his way back past the
castle and out upon the high road which led down to Nagy-Károly.
Through the greater part of the night he walked, until at a small
mountain village he was able to induce a peasant to harness a horse
and drive him into the town.
Before nine o’clock that morning he called upon the chief of police,
and through a man who spoke French, gave him a description of the
secret wireless set, and of the dastardly plot to kill him and dispose
of his body by burying it in the forest.
At once the police official was on the alert, for the Schloss Zenta, he
said, belonged to a certain young Count Böckh, who was a minor,
and at the university of Budapest. He had never heard of the Baron,
who had, no doubt, established himself there unknown to its rightful
owner, but pretending to the servants that he had rented it
furnished. This was later on ascertained to be a fact.
Within an hour urgent telegrams were exchanged between the
Ministry of Police in Budapest and the chief at Nagy-Károly, so that
at noon, when the Baron and Koblitz put in an appearance at the
railway station—intending to fly after finding that Falconer had gone
and that the secret wireless station had been put out of action—they
were at once arrested and sent by the next train under escort to
Budapest.
Later, after much inquiry, the police discovered that the pseudo-
Baron—whose real name was Franz Haynald, a well-known
revolutionist—had, with Koblitz and a number of others, formed a
great and widespread political plot, financed by Germany, to effect a
union with Hungary and Bavaria. Austria was to be overthrown,
Vienna occupied jointly by Bavarian and Hungarian troops, and
Czecho-Slovakia was to be blindfolded by creating a revolution in
Jugo-Slavia. The idea was, with the aid of Tzarist Russia, to establish
a great “New Germany,” which was to be more powerful than ever,
and become mistress of the world.
This certainly would have been attempted—for the erecting of that
powerful wireless station was one of the first steps—had not
Geoffrey Falconer acted with such boldness and decision.
Haynald, with Françoise—who was the daughter of the man Koblitz—
Koblitz himself, the servant Karl, and twenty others are all now
undergoing long sentences of imprisonment.
CHAPTER VII
THE POISON FACTORY

Geoffrey Falconer stood at the window of the big old Adams room at
the Savage Club, chatting with a journalist friend, Charles—alias
“Doggy”—Wentworth, of the Daily Mail.
Before them lay Adelphi Terrace and beyond the Embankment and
the broad grey Thames with its wharves on the Surrey bank,
London’s silent highway.
It was the luncheon hour on a day in early spring. The trees along
the Embankment, and in the Gardens below, wore their fresh bright
green, not yet dulled by the London smoke, while along the
Embankment the trams were rolling heavily between the bridges of
Blackfriars and Westminster.
The room in which they stood was familiar to Bohemian London—the
world of painters, poets, actors, novelists, sculptors, journalists, and
scientists, who lunch and smoke in the same great room with its
portraits, caricatures, and trophies—perhaps the only spot on earth
where a man’s worth is nowadays not judged by his pocket or the
estimation of his own importance. Confined to the professions, it is a
club where as long as a man is a good fellow and has no side he is
popular. But woe betide the member who betrays the slightest
leaning towards egotism.
The members, leaving the little back bar, had already begun to drift
in to take their places at the little tables which occupied half the big
common-room. The unconventional shouts of “Hulloa, Tommie!”
“Hulloa, Jack!” “Hulloa, Max!” were heard on every side—Christian
names and nicknames of men some of whose names were in the
homes of England and America as household words, men of mark
whose portraits greeted one every day in the picture papers.
Just as “Doggy” was about to turn aside with his guest, a friend of
his approached the pair. A tall, lank man with a furrowed face,
“Dicky” Peters, foreign editor of the great London journal, the Daily
Telephone, was known to both, as indeed he was known to every
journalist in London.
“Well, Dicky, what’s the latest?” asked Wentworth, a man ten years
his junior, but who was among the most brilliant men in Fleet Street.
“Oh, nothing much,” laughed the other good-humouredly. “Only that
infernal Moscow wireless press. It gets on one’s nerves.”
“How?” asked Geoffrey, at once on the alert.
“Let’s go and feed, and I’ll tell you.”
The trio went past the row of old leather-covered couches from the
“smoking-room” to the “dining-room,” between which there was no
partition, and presently as they discussed a plain English luncheon
which even peers as guests did not disdain—for every one is on
equality in the Savage—Peters began to rail at the wireless reports
from Moscow.
“Well, Falconer’s a Marconi man,” remarked Wentworth. “Perhaps he
can explain.”
“I don’t understand it at all,” Geoffrey said. “Of course I’m on the
engineering side. I don’t know much about the operating side—
except in experimenting.”
“Well, I think the whole thing is most puzzling.”
“How?”
“Well, one day we get the wireless press from Russia and publish it.
Next day we have an entirely different and contradictory version.
And, oh! the Bolshevik propaganda—well, you see it in many papers.
Sub-editors all over the country are using no discretion. We get all
the jumble of facts, fictions, declarations, but I never publish any.
This latest propaganda against Britain is most pernicious. In America
they are publishing all sorts of inflammatory stuff against us
regarding Ireland—all of it emanating from the Third International—
or whatever they call themselves.”
“The Bolshevik press news should be wiped out,” declared “Doggy”
Wentworth. “No sane man who reads it ever believes in the glorious
and prosperous state of Russia under Lenin!”
“I agree,” said Falconer, interested in the conversation between the
two journalists. “I often listen to ‘M.S.K.’ at night and read him, but
his stories are of such a character that I wonder any newspaper
publishes them. We never refer to it in our Marconi Press which we
send out each night to the cross-Atlantic ships.”
“Yes, but how about the revolutionary propaganda regarding
Ireland? We get a pile of it in the office every night,” said Peters. “I
never publish it, but over in America they get it too, and I’m certain
it does Britain incalculable harm.”
It was at a moment when a wave of Bolshevism was sweeping
across Europe, a hostility to culture and to intelligence which had, in
Russia, brought about a terrorism which was assisted by a police
system which left far behind it the ideas and the proceedings of the
Tsar’s secret police. And those responsible for the chaos in Russia
were, it was known, endeavouring to stir up revolution in Great
Britain, and thus assist Germany in her defiant attitude towards the
Allies.
That night the young Marconi engineer dined at Mrs. Beverley’s, and
sat beside Sylvia. Only three other guests were present, a well-
known peer and his wife, and a prominent member of the
Government, Mr. Charles Warwick.
Over the dinner table, in consequence of some serious reports in
that night’s newspaper concerning the advance of the Red Army in
the south of Russia, the conversation turned upon the situation, Mr.
Warwick expressing an opinion that half the news concerning the
Red successes was incorrect.
“I agree,” declared Falconer. “Only this morning I was discussing the
same subject with two journalists in the Savage Club. It seems that
Lenin and his friends are sending out by wireless all sorts of untruths
concerning our rule in Ireland—allegations calculated to incense
other countries against us.”
“Well, if that’s so, Geoffrey, why don’t you wireless people try to
suppress them?” remarked Sylvia.
“An excellent suggestion!” laughed the smooth-haired young fellow.
“But I’m afraid it would be impossible to stop the wireless waves
they send out from Moscow each evening. When you press a
wireless key the waves radiate in every direction, and reach far and
wide. There is no invention yet to suppress wireless signals, except
to jam them by sending out stronger ones upon the same wave-
length. That can, of course, be done, but it would interfere with all
wireless traffic.”
“Somebody really ought to blow up the Moscow wireless station,”
declared Lord Cravenholme, an elderly blunt man, whose wife was
many years his junior.
“Yes,” agreed Warwick. “The sooner somebody puts an end to their
lie-factory the better.”
“Britain’s enemies are always ready enough to believe any fiction
alleged against her. And, of course, the crafty Germans are behind
all these attempts to stir strife,” his lordship declared, poising his
hock-glass in his hand.
“Well,” exclaimed Sylvia, “I really think there’s an excellent chance
for you, Geoffrey.” And she laughed merrily.
“Yes,” added her mother, “If you could manage to stop it all, you
would certainly be a public benefactor, Mr. Falconer. I read in the
American papers I get over some very nasty things about you here—
all of it emanating, no doubt, from enemy and revolutionary
sources.”
“Ah! Mrs. Beverley,” exclaimed the young Marconi man, “I’m afraid
that such a task is beyond me. In the first place, nobody can get
into Russia just now. Again, if the station were wrecked, Lenin’s
people would soon rig up another. So I fear that we are suggesting
the impossible.”
Later that evening, when Geoffrey and Sylvia were alone together in
the morning-room—the others being in the big upstairs drawing-
room—the girl mentioned that the odious fortune-hunter, Lord
Hendlewycke, was to take them by car on the following day to tea at
the Burford Bridge Hotel, at Box Hill.
“Oh, how I detest him!” said the pretty girl with a sigh. “And yet
mother is for ever asking him here. I’m sick of it all. Wherever we go
he turns up.”
“Because your mother has set her mind upon your becoming Lady
Hendlewycke,” he said in a low, intense voice. “Why is she in London
—except to marry you to somebody with a title? I know it’s a very
horrid way of putting it, dearest, but nevertheless it is the truth.”
“I know,” she sighed. “But I hate the fellow—I hate him! I’m for ever
having headaches, and pretending a chill in order to avoid meeting
him. But he is so horribly persistent.”
He took her in his strong arms and kissed her fondly, saying:
“Never mind. Be patient, dearest. He will grow weary very soon. Be
patient—for my sake!”
But at that moment the footman entered, and springing apart, they
rejoined the others upstairs.
Geoffrey could only remain for half an hour, as he had to catch his
train from Liverpool Street. He was back at Warley just before
eleven. His sombre old home was all quiet, for the servants had
retired, and his father was busy writing in his study when Geoffrey
entered.
Together they smoked for about a quarter of an hour, after which his
father extinguished his oil reading-lamp and retired.
Geoffrey, as was his habit before turning in, entered his wireless
room wherein he had fitted that most up-to-date set—a bewildering
array of apparatus—chief among which was his improved amplifier
and a double note magnifier of his own design.
He placed the telephones over his ears, and having switched on the
seven little glow lamps or valves of the amplifier, and the two others
of the magnifier, tuned-in one or two stations.
“G.F.A.A.G.”—a great airship to wireless men—was out upon a night
cruise from Pulham, in Norfolk, over England. He soon picked her
up, and heard her taking her bearings from the direction-finding
station at Flamborough, on the Yorkshire coast. After which she
spoke by wireless telephony to her base at Pulham, and then to
Croydon, Lympe, near Folkestone, and to St. Inglevert in France.
Afterwards she carried on a conversation with the air stations at
Renfrew and Castle Bromwich. She was told by Flamborough that
her position was thirty miles due north of Cardiff, going westward.
Such was one of the wonders of wireless.
His thoughts, however, were elsewhere. He was still pondering over
those budgets of lies sent out from Moscow four of five times each
twenty-four hours.
He placed his hand upon the knob of his “tuner,” and raised his
wave-length to five thousand mètres. Other stations were
transmitting, but he heard nothing of “M.S.K.”—the call-letters
assigned to Moscow. Higher he raised the wave-length until, on
seven thousand six hundred mètres, he found that high-pitched
continuous-wave note, which he recognised as the lying voice from
the ether.
He took up a pencil and began to write down rapidly in French a
most scurrilous and untrue allegation against British rule in Ireland,
intended for the anti-British press in America.
Halfway through he flung down the pencil with an exclamation of
disgust, and removing the “Brown” head-’phones, switched off, and
went upstairs to bed.
Next day, at the Marconi Works at Chelmsford, he discussed with
several of his fellow-engineers the scandal of the Moscow Bolshevik
propaganda, but each of them declared that nothing could be done
to suppress it. Lenin and Trotsky ruled Red Russia, and certainly the
tide of lies sent out broadcast into space could not be stemmed.
Sylvia’s words constantly recurred to him. She had urged him to do
something to stifle the pernicious propaganda against law and order
in Great Britain. But how?
Many days went by. He was busy in the experimental laboratory up
at Marconi House, and had but little time to devote to anything
except the highly scientific problem which he was assisting three
great wireless experts to try to solve.
About three weeks had passed when one afternoon he happened to
be in the great airy apartment at Chelmsford where various
instruments were being subjected to severe tests before being
passed as “O.K.”—note-magnifiers, direction-finders, calling-devices,
amplifiers, and all the rest—when, with the telephones on his ears,
he heard Moscow sending out “C.Q.”—or a request for all to listen.
Then again came that never-ending praise of Soviet Russia, which,
under the absolute rule of a little group of men, mostly Russian or
German Jews obeying the orders of Lenin—the new Ivan the Terrible
—and his war minister, Trotsky, was, it was said, converting Russia
into a terrestrial paradise. On the contrary, it was well known that
Russia was a terrestrial hell, where torture was deliberately being
used on a great scale, and with a cruelty that had never been
surpassed, even by the Spanish Inquisition. The recapture of
Kharkoff by Deniken had revealed a most terrible state of affairs,
atrocities of which even the terrible Turks would have been
ashamed. And yet the Moscow wireless was inviting the people of
Britain and America to rise and establish a similar régime!
As Geoffrey listened attentively, his ear trained to the variations of
the sound of the signals of different stations, it suddenly occurred to
him that the “note” was slightly different from that which he had
heard and discarded on so many occasions.

You might also like