SlideShare a Scribd company logo
1 of 46
Download to read offline
Getting Started with Cross
Platform Development
using Flutter
Wei-Meng Lee
Developer Learning Solutions
www.learn2develop.net
@weimenglee
weimenglee@learn2develop.net
README
Agenda
• Cross-Platform Development Frameworks
• Getting Started with Flutter
• Demos!
Developing for the Mobile
Platforms
• Two dominant platforms
• iOS
• Android
• Others have come and go
• Symbian
• Windows Phone
• Blackberry OS
• Bada and Tizen
• Sailfish
?
New Platform?
• Huawei’s own mobile OS - HongMeng
• Rumored to be built with the help of former Nokia engineers
• Gradually replace Android; used on smartphone, tablet, TV, automobile,
wearable; compatible with all Android apps
• Uphill task
• Needs a lot of traction to succeed
• Necessary to have a strong tool chain for developers
• Open up to the non-Chinese speaking world
• Needs a strong app-store
• Microsoft and Amazon have struggled for years
鸿蒙
Cross Platform
Development
Cross Platform
Development Solutions
• Hybrid Apps / Web Apps
• PhoneGap, Ionic, PWA
• True Native Apps
• Xcode, Android Studio, Xamarin, React Native,
Flutter
Xamarin
• Founded by the same people who created Mono
• Uses C#
• Now owned by Microsoft
• Has the following components:
• Xamarin.iOS
• Xamarin.Android
• Xamarin.Mac
• Xamarin.Forms
How Xamarin
Works
Shared Code
Database Access
Web Services Access
Business Logic
Android UI Code iOS UI Code
Xamarin.Android Xamarin.iOS
Xamarin.Forms
Shared Code
Database Access
Web Services Access
Business Logic
Xamarin.Forms
• UI rendered based on the platform’s UI
widget
React Native
• React Native is a JavaScript framework for writing native iOS and
Android apps
• based on React, Facebook's JavaScript library for building UI
• React Native apps are written using a mixture of:
• JavaScript
• CSS
• JSX (Javascript Extension) = JS + XML
• React Native translates your UI markup to native UI elements,
hence your app is a pure native app
How React Native Works
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
);
}
iOS
Android
???
Metro
Bundler
<View>
UIView
View
React Native
iOS
Android
JavaScriptCore
JavaScriptCore
http://localhost:8081/index.bundle?platform=android•
http://localhost:8081/index.bundle?platform
=ios
• UI rendered based on the platform’s UI widget
Flutter
• Google’s portable UI toolkit for building natively-compiled mobile,
web, and desktop apps
• Uses Google’s Dart programming language
• It has the following major components:
• Flutter engine - written in C++, provides low-levels rendering
support using Google’s Skia graphics library
• Foundation Library - written in Dart, provides a base layer of
functionality for apps and APIs to communicate with the engine
• Widgets - basic building blocks for UI
Platform Widgets
• Unlike Xamarin and React Native, Flutter does
not use the platform’s native widgets
• Instead, Flutter provides a set of widgets
(including Material Design and Cupertino
(iOS) widgets), managed and rendered by
Flutter’s framework and engine
How Flutter Works
Dart
Widgets
Render
Engine
Platform Channels
Canvas
Events
FlutterApp Platform
Camera Audio Location Sensors
Platform APIs
• Flutter does not rely on the device’s OEM widgets - it renders every
view component using its own high-performance rendering engine
• Widgets are rendered onto a Skia canvas and sent to the platform.
The platform shows the canvas and sends events back
Comparing the Frameworks
iOS Android Xamarin React Native Flutter
From Apple Google Microsoft Facebook Google
Language
Objective-C/
Swift
Java/Kotlin C# ECMAScript Dart
IDE Xcode Android Studio Visual Studio
Visual Studio
Code
Visual Studio
Code
Package
Manager
Swift Package
Manager/
CocoaPods
Gradle/Maven Nuget npm pub
UI Native Native Native Native Rendered
Dart
• Dart is a programming language developed by Google
• Similar to Java, C#, Swift, Kotlin
• For development, Dart uses JIT (Just In Time)
compilation
• For release, Dart uses AOT (Ahead Of Time) to
compile to fast native code
• Dart can also be compiled to JavaScript, to be used
on the web
Download the Dart Cheat
Sheet
• http://bit.ly/2uCSLE3
Demo
• Creating a Flutter Project
• $ flutter create hello_world
Structure of a Flutter
Project
• lib/
• Contains code for your app
• pubspec.yaml
• Stores the list of packages needed by your app
• ios/android
• Code specific to iOS and Android; sets permission
for your app, e.g. location, Bluetooth, etc
Running a Flutter Project
• $ flutter emulators
• $ flutter emulators --launch apple_ios_simulator
• $ cd hello_world
• $ flutter run
A BareBone Flutter Project
import 'package:flutter/material.dart';
void main() => runApp(
Text(
'Hello, Riga!',
textDirection: TextDirection.ltr,
),
);
runApp() has a widget argument
This argument will become the root widget for the whole app
Hot-reload has no effect on the root widget
Text is a widget
Widgets
• In Flutter, UI are represented as Widgets
• Widgets was inspired by React
• Widgets describe how the view should look like,
given its current configuration and state
• When the state changes, the widget rebuilds its
description, and the framework compares it with
the previous description to determine the
minimal changes needed to update the UI
Center
import 'package:flutter/material.dart';
void main() => runApp(
Center(
child:Text(
'Hello, Riga!',
textDirection: TextDirection.ltr,
),
)
);
Center is a widget that aligns another widget
Container
void main() => runApp(
Center(
child: Container(
margin: const EdgeInsets.all(10.0),
color: Color(0xFFFFBF00),
width: 100.0,
height: 100.0,
),
),
);
Container is a a convenience widget that
combines common painting, positioning, and
sizing widgets.
Child within a Container
void main() => runApp(
Center(
child: Container(
margin: const EdgeInsets.all(10.0),
color: Color(0xFFFFBF00),
width: 300.0,
height: 100.0,
child: Center(
child:Text(
'Hello, Riga!',
textDirection: TextDirection.ltr,
style:TextStyle(
color:Color(0xFF000000),
fontSize:32,
)
),
),
),
),
);
MaterialApp
void main() => runApp(
MaterialApp(
title: 'Material App Demo',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Demo'),
),
body: Center(
child: Text('Hello Riga'),
),
),
)
);
• The MaterialApp class represents an
application that uses material design
• It implements the Material design language for
iOS, Android, and web.
Adding Widgets to the
Bodyvoid main() => runApp(
MaterialApp(
title: 'Material App Demo',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Demo'),
),
body: Center(
child: Container(
margin: const EdgeInsets.all(10.0),
color: Color(0xFFFFBF00),
width: 300.0,
height: 100.0,
child: Center(
child:Text(
'Hello, Riga!',
textDirection: TextDirection.ltr,
style:TextStyle(
color:Color(0xFF000000),
fontSize:32,
)
),
),
),
),
),
)
);
CupertinoApp
• The CupertinoApp class represents an application
that uses Cupertino design
• It implements the current iOS design language based
on Apple's Human Interface Guidelines.
import 'package:flutter/cupertino.dart';
void main() => runApp(
CupertinoApp(
title: 'Cupertino App Demo',
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: const Text('Cupertino App Demo'),
),
child: Center(
child: Text('Hello Riga'),
),
)
),
);
Types of Widgets
• Stateless widgets
• Changing the properties of stateless widgets
has no effect on the rendering of the widget
• Stateful widgets
• Changing the properties of stately widgets will
trigger the life cycle hooks and update its UI
using the new state
Creating a Stateless Widget
• To create a stateless widget:
• Name the new Widget class
• Extend the class from StatelessWidget
• Implement the build() method, with one argument of type
BuildContext and return type of Widget
class MyCustomWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return null;
}
}
Defining the Stateless Widget
class MyCustomWidget extends StatelessWidget {
// all properties in stateless widget must declare with final or const
final String name;
// class constructor
MyCustomWidget(this.name);
@override
Widget build(BuildContext context) {
return Center(
child: Container(
margin: const EdgeInsets.all(10.0),
color: Color(0xFFFFBF00),
width: 300.0,
height: 100.0,
child: Center(
child: Text(
'Hello, $name!',
textDirection: TextDirection.ltr,
style: TextStyle(
color: Color(0xFF000000),
fontSize: 32,
)
),
),
),
);
}
}
Using the Stateless Widget
void main() => runApp(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, world!',
),
MyCustomWidget("Riga"),
],
),
),
),
);
Using the Stateless Widget
void main() => runApp(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, world!',
),
MyCustomWidget("Riga"),
MyCustomWidget("Singapore"),
],
),
),
),
);
Hot Reload@override
Widget build(BuildContext context) {
return Center(
child: Container(
margin: const EdgeInsets.all(10.0),
color: Color(0xFFFFBF00),
width: 300.0,
height: 100.0,
child: Center(
child:Text(
'Welcome!, $name!',
textDirection: TextDirection.ltr,
style:TextStyle(
color: Color(0xFF000000),
fontSize:32,
)
),
),
),
);
}
class MyCustomStatefulWidget extends StatefulWidget {
MyCustomStatefulWidget({Key key, this.country}) : super(key: key);
final String country;
@override
_DisplayState createState() => _DisplayState();
}
class _DisplayState extends State<MyCustomStatefulWidget> {
int counter = 0;
@override
Widget build(BuildContext context) {
return Center(
...
);
}
}
Stateful Widgets
Doesn’t contain state or UI
representation
Contains the state and UI
• Stateful widgets do not exist by themselves; they
require an extra class to store the state of the widget
class _DisplayState extends State<MyCustomStatefulWidget> {
int counter = 0;
@override
Widget build(BuildContext context) {
return Center(
child: Container(
margin: const EdgeInsets.all(10.0),
color: Color(0xFFFFBF00),
width: 300.0,
height: 100.0,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
...
],
),
),
)
);
}
}
...
children: <Widget>[
Text(
widget.country,
textDirection: TextDirection.ltr,
style:TextStyle(
color: Color(0xFF000000),
fontSize:32,
)
),
Center(
child: GestureDetector(
onTap: () {
setState(() {
++counter;
});
},
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Color(0xFF17A2B8),
),
child: Center(
child: Text(
'$counter',
style: TextStyle(fontSize: 25.0),
),
),
),
),
),
],
...
Using the Stateful Widget
import 'package:flutter/material.dart';
void main() => runApp(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, world!',
),
MyCustomStatefulWidget(country: "Riga"),
MyCustomStatefulWidget(country: "Singapore"),
],
),
),
),
);
GestureDetector
Center(
child: GestureDetector(
onTap: () {
setState(() {
++counter;
});
},
onLongPress: () {
setState(() {
--counter;
});
},
child: Container(
…
• The GestureDetector widget
doesn’t have a visual representation
but instead detects gestures made
by the user
• When the user taps the Container,
the GestureDetector calls its
onTap callback
• You can use GestureDetector to
detect a variety of input gestures,
including taps, drags, and scales.
Using the Stateful Widget
in a Material App
void main() => runApp(
MaterialApp(
title: 'Material App Demo',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, world!',
),
MyCustomStatefulWidget(country: "Riga"),
MyCustomStatefulWidget(country: "Singapore"),
],
),
),
),
)
);
Combining Stateless and
Stateful Widgets
void main() => runApp(
MaterialApp(
title: 'Material App Demo',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Hello, world!',
),
MyCustomStatefulWidget(country: "Riga"),
MyCustomStatefulWidget(country: "Singapore"),
MyCustomWidget("Latvia"),
],
),
),
),
)
);
Packages
• Flutter supports using shared packages contributed
by other developers
• Some commonly used packages:
• http
• location
• google_maps_flutter
• flutter_local_notifications
Demos
Thank You!

More Related Content

What's hot

What's hot (20)

Flutter talkshow
Flutter talkshowFlutter talkshow
Flutter talkshow
 
Mobile development with Flutter
Mobile development with FlutterMobile development with Flutter
Mobile development with Flutter
 
Flutter Intro
Flutter IntroFlutter Intro
Flutter Intro
 
Intro to Flutter SDK
Intro to Flutter SDKIntro to Flutter SDK
Intro to Flutter SDK
 
All a flutter about Flutter.io
All a flutter about Flutter.ioAll a flutter about Flutter.io
All a flutter about Flutter.io
 
Intro to Flutter
Intro to FlutterIntro to Flutter
Intro to Flutter
 
The magic of Flutter - Amman ioextended 6-7-2019
The magic of Flutter - Amman ioextended 6-7-2019The magic of Flutter - Amman ioextended 6-7-2019
The magic of Flutter - Amman ioextended 6-7-2019
 
Flutter not yet another mobile cross-platform framework - i ox-kl19
Flutter   not yet another mobile cross-platform framework - i ox-kl19Flutter   not yet another mobile cross-platform framework - i ox-kl19
Flutter not yet another mobile cross-platform framework - i ox-kl19
 
Cross-Platform App Development with Flutter, Xamarin, React Native
Cross-Platform App Development with Flutter, Xamarin, React NativeCross-Platform App Development with Flutter, Xamarin, React Native
Cross-Platform App Development with Flutter, Xamarin, React Native
 
Flutter introduction
Flutter introductionFlutter introduction
Flutter introduction
 
Flutter 1
Flutter 1Flutter 1
Flutter 1
 
Mobile DevOps pipeline using Google Flutter
Mobile DevOps pipeline using Google FlutterMobile DevOps pipeline using Google Flutter
Mobile DevOps pipeline using Google Flutter
 
Getting Started with Cross-Platform Mobile Development with Flutter and Dart
Getting Started with Cross-Platform Mobile Development with Flutter and DartGetting Started with Cross-Platform Mobile Development with Flutter and Dart
Getting Started with Cross-Platform Mobile Development with Flutter and Dart
 
Flutter festival Info session -2022
Flutter festival Info session -2022Flutter festival Info session -2022
Flutter festival Info session -2022
 
Building Beautiful Apps using Google Flutter
Building Beautiful Apps using Google FlutterBuilding Beautiful Apps using Google Flutter
Building Beautiful Apps using Google Flutter
 
Flutter Development Services
Flutter Development ServicesFlutter Development Services
Flutter Development Services
 
Flutter for web
Flutter for web Flutter for web
Flutter for web
 
The Magic of flutter Comex oman 2019
The Magic of flutter Comex oman 2019The Magic of flutter Comex oman 2019
The Magic of flutter Comex oman 2019
 
Flutter app
Flutter appFlutter app
Flutter app
 
Null safety in dart and flutter , the whole story!
Null safety in dart and flutter , the whole story!Null safety in dart and flutter , the whole story!
Null safety in dart and flutter , the whole story!
 

Similar to Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile focused 75th DevClub.lv

GoogleDSC_ GHRCE_ flutter_firebase.pptx
GoogleDSC_ GHRCE_  flutter_firebase.pptxGoogleDSC_ GHRCE_  flutter_firebase.pptx
GoogleDSC_ GHRCE_ flutter_firebase.pptx
GoogleDeveloperStude22
 
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGapBuilding Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Nick Landry
 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual Studio
Mizanur Sarker
 

Similar to Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile focused 75th DevClub.lv (20)

flutterbootcamp
flutterbootcampflutterbootcamp
flutterbootcamp
 
flutter_bootcamp_MUGDSC_Presentation.pptx
flutter_bootcamp_MUGDSC_Presentation.pptxflutter_bootcamp_MUGDSC_Presentation.pptx
flutter_bootcamp_MUGDSC_Presentation.pptx
 
#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart
 
Mobile Application Development class 001
Mobile Application Development class 001Mobile Application Development class 001
Mobile Application Development class 001
 
GoogleDSC_ GHRCE_ flutter_firebase.pptx
GoogleDSC_ GHRCE_  flutter_firebase.pptxGoogleDSC_ GHRCE_  flutter_firebase.pptx
GoogleDSC_ GHRCE_ flutter_firebase.pptx
 
Choose flutter
Choose flutterChoose flutter
Choose flutter
 
22Flutter.pdf
22Flutter.pdf22Flutter.pdf
22Flutter.pdf
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and Firebase
 
React Native
React NativeReact Native
React Native
 
Flutter Leap of Faith
Flutter Leap of FaithFlutter Leap of Faith
Flutter Leap of Faith
 
NCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile AppsNCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile Apps
 
Cross-platform Mobile Development on Open Source
Cross-platform Mobile Development on Open SourceCross-platform Mobile Development on Open Source
Cross-platform Mobile Development on Open Source
 
Build Your First iPhone or Android App with Telerik AppBuilder
Build Your First iPhone or Android App with Telerik AppBuilderBuild Your First iPhone or Android App with Telerik AppBuilder
Build Your First iPhone or Android App with Telerik AppBuilder
 
Apache cordova
Apache cordovaApache cordova
Apache cordova
 
Cross Platform Mobile App Development
Cross Platform Mobile App DevelopmentCross Platform Mobile App Development
Cross Platform Mobile App Development
 
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGapBuilding Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
Building Mobile Cross-Platform Apps with HTML5, jQuery Mobile & PhoneGap
 
Cross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual StudioCross-Platform Development using Angulr JS in Visual Studio
Cross-Platform Development using Angulr JS in Visual Studio
 
Developing a native mobile apps using Ionic&Cordova
Developing a native mobile apps using Ionic&CordovaDeveloping a native mobile apps using Ionic&Cordova
Developing a native mobile apps using Ionic&Cordova
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
 
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
Shifting landscape of mobile automation, and the future of Appium - Jonathan ...
 

More from DevClub_lv

More from DevClub_lv (20)

Fine-tuning Large Language Models by Dmitry Balabka
Fine-tuning Large Language Models by Dmitry BalabkaFine-tuning Large Language Models by Dmitry Balabka
Fine-tuning Large Language Models by Dmitry Balabka
 
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ..."Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
"Infrastructure and AWS at Scale: The story of Posti" by Goran Gjorgievski @ ...
 
From 50 to 500 product engineers – data-driven approach to building impactful...
From 50 to 500 product engineers – data-driven approach to building impactful...From 50 to 500 product engineers – data-driven approach to building impactful...
From 50 to 500 product engineers – data-driven approach to building impactful...
 
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
Why is it so complex to accept a payment? by Dmitry Buzdin from A-Heads Consu...
 
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
Do we need DDD? by Jurijs Čudnovskis from “Craftsmans Passion” at Fintech foc...
 
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
Network security with Azure PaaS services by Erwin Staal from 4DotNet at Azur...
 
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
Using Azure Managed Identities for your App Services by Jan de Vries from 4Do...
 
SRE (service reliability engineer) on big DevOps platform running on the clou...
SRE (service reliability engineer) on big DevOps platform running on the clou...SRE (service reliability engineer) on big DevOps platform running on the clou...
SRE (service reliability engineer) on big DevOps platform running on the clou...
 
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
Emergence of IOT & Cloud – Azure by Narendra Sharma at Cloud focused 76th Dev...
 
Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
In the Trenches During a Software Supply Chain Attack by Mitch Denny at Front...
 
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
Software Decision Making in Terms of Uncertainty by Ziv Levy at FrontCon 2019
 
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
V8 by example: A journey through the compilation pipeline by Ujjwas Sharma at...
 
Bridging the gap between UX and development - A Storybook by Marko Letic at F...
Bridging the gap between UX and development - A Storybook by Marko Letic at F...Bridging the gap between UX and development - A Storybook by Marko Letic at F...
Bridging the gap between UX and development - A Storybook by Marko Letic at F...
 
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
Case-study: Frontend in Cybersecurity by Ruslan Zavacky by FrontCon 2019
 
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
Building next generation PWA e-commerce frontend by Raivis Dejus at FrontCon ...
 
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
 
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019Managing State in React Apps with RxJS by James Wright at FrontCon 2019
Managing State in React Apps with RxJS by James Wright at FrontCon 2019
 
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
AAA 3D GRAPHICS ON THE WEB WITH REACTJS + BABYLONJS + UNITY3D by Denis Radin ...
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Cross Platform Mobile Development using Flutter by Wei Meng Lee at Mobile focused 75th DevClub.lv

  • 1. Getting Started with Cross Platform Development using Flutter Wei-Meng Lee Developer Learning Solutions www.learn2develop.net @weimenglee weimenglee@learn2develop.net
  • 3. Agenda • Cross-Platform Development Frameworks • Getting Started with Flutter • Demos!
  • 4. Developing for the Mobile Platforms • Two dominant platforms • iOS • Android • Others have come and go • Symbian • Windows Phone • Blackberry OS • Bada and Tizen • Sailfish
  • 5. ?
  • 6. New Platform? • Huawei’s own mobile OS - HongMeng • Rumored to be built with the help of former Nokia engineers • Gradually replace Android; used on smartphone, tablet, TV, automobile, wearable; compatible with all Android apps • Uphill task • Needs a lot of traction to succeed • Necessary to have a strong tool chain for developers • Open up to the non-Chinese speaking world • Needs a strong app-store • Microsoft and Amazon have struggled for years 鸿蒙
  • 8. Cross Platform Development Solutions • Hybrid Apps / Web Apps • PhoneGap, Ionic, PWA • True Native Apps • Xcode, Android Studio, Xamarin, React Native, Flutter
  • 9. Xamarin • Founded by the same people who created Mono • Uses C# • Now owned by Microsoft • Has the following components: • Xamarin.iOS • Xamarin.Android • Xamarin.Mac • Xamarin.Forms
  • 10. How Xamarin Works Shared Code Database Access Web Services Access Business Logic Android UI Code iOS UI Code Xamarin.Android Xamarin.iOS
  • 11. Xamarin.Forms Shared Code Database Access Web Services Access Business Logic Xamarin.Forms • UI rendered based on the platform’s UI widget
  • 12. React Native • React Native is a JavaScript framework for writing native iOS and Android apps • based on React, Facebook's JavaScript library for building UI • React Native apps are written using a mixture of: • JavaScript • CSS • JSX (Javascript Extension) = JS + XML • React Native translates your UI markup to native UI elements, hence your app is a pure native app
  • 13. How React Native Works render() { return ( <View style={styles.container}> <Text style={styles.welcome}> Welcome to React Native! </Text> </View> ); } iOS Android ??? Metro Bundler <View> UIView View React Native iOS Android JavaScriptCore JavaScriptCore http://localhost:8081/index.bundle?platform=android• http://localhost:8081/index.bundle?platform =ios • UI rendered based on the platform’s UI widget
  • 14. Flutter • Google’s portable UI toolkit for building natively-compiled mobile, web, and desktop apps • Uses Google’s Dart programming language • It has the following major components: • Flutter engine - written in C++, provides low-levels rendering support using Google’s Skia graphics library • Foundation Library - written in Dart, provides a base layer of functionality for apps and APIs to communicate with the engine • Widgets - basic building blocks for UI
  • 15. Platform Widgets • Unlike Xamarin and React Native, Flutter does not use the platform’s native widgets • Instead, Flutter provides a set of widgets (including Material Design and Cupertino (iOS) widgets), managed and rendered by Flutter’s framework and engine
  • 16. How Flutter Works Dart Widgets Render Engine Platform Channels Canvas Events FlutterApp Platform Camera Audio Location Sensors Platform APIs • Flutter does not rely on the device’s OEM widgets - it renders every view component using its own high-performance rendering engine • Widgets are rendered onto a Skia canvas and sent to the platform. The platform shows the canvas and sends events back
  • 17. Comparing the Frameworks iOS Android Xamarin React Native Flutter From Apple Google Microsoft Facebook Google Language Objective-C/ Swift Java/Kotlin C# ECMAScript Dart IDE Xcode Android Studio Visual Studio Visual Studio Code Visual Studio Code Package Manager Swift Package Manager/ CocoaPods Gradle/Maven Nuget npm pub UI Native Native Native Native Rendered
  • 18. Dart • Dart is a programming language developed by Google • Similar to Java, C#, Swift, Kotlin • For development, Dart uses JIT (Just In Time) compilation • For release, Dart uses AOT (Ahead Of Time) to compile to fast native code • Dart can also be compiled to JavaScript, to be used on the web
  • 19. Download the Dart Cheat Sheet • http://bit.ly/2uCSLE3
  • 20. Demo • Creating a Flutter Project • $ flutter create hello_world
  • 21. Structure of a Flutter Project • lib/ • Contains code for your app • pubspec.yaml • Stores the list of packages needed by your app • ios/android • Code specific to iOS and Android; sets permission for your app, e.g. location, Bluetooth, etc
  • 22. Running a Flutter Project • $ flutter emulators • $ flutter emulators --launch apple_ios_simulator • $ cd hello_world • $ flutter run
  • 23. A BareBone Flutter Project import 'package:flutter/material.dart'; void main() => runApp( Text( 'Hello, Riga!', textDirection: TextDirection.ltr, ), ); runApp() has a widget argument This argument will become the root widget for the whole app Hot-reload has no effect on the root widget Text is a widget
  • 24. Widgets • In Flutter, UI are represented as Widgets • Widgets was inspired by React • Widgets describe how the view should look like, given its current configuration and state • When the state changes, the widget rebuilds its description, and the framework compares it with the previous description to determine the minimal changes needed to update the UI
  • 25. Center import 'package:flutter/material.dart'; void main() => runApp( Center( child:Text( 'Hello, Riga!', textDirection: TextDirection.ltr, ), ) ); Center is a widget that aligns another widget
  • 26. Container void main() => runApp( Center( child: Container( margin: const EdgeInsets.all(10.0), color: Color(0xFFFFBF00), width: 100.0, height: 100.0, ), ), ); Container is a a convenience widget that combines common painting, positioning, and sizing widgets.
  • 27. Child within a Container void main() => runApp( Center( child: Container( margin: const EdgeInsets.all(10.0), color: Color(0xFFFFBF00), width: 300.0, height: 100.0, child: Center( child:Text( 'Hello, Riga!', textDirection: TextDirection.ltr, style:TextStyle( color:Color(0xFF000000), fontSize:32, ) ), ), ), ), );
  • 28. MaterialApp void main() => runApp( MaterialApp( title: 'Material App Demo', home: Scaffold( appBar: AppBar( title: Text('Material App Demo'), ), body: Center( child: Text('Hello Riga'), ), ), ) ); • The MaterialApp class represents an application that uses material design • It implements the Material design language for iOS, Android, and web.
  • 29. Adding Widgets to the Bodyvoid main() => runApp( MaterialApp( title: 'Material App Demo', home: Scaffold( appBar: AppBar( title: Text('Material App Demo'), ), body: Center( child: Container( margin: const EdgeInsets.all(10.0), color: Color(0xFFFFBF00), width: 300.0, height: 100.0, child: Center( child:Text( 'Hello, Riga!', textDirection: TextDirection.ltr, style:TextStyle( color:Color(0xFF000000), fontSize:32, ) ), ), ), ), ), ) );
  • 30. CupertinoApp • The CupertinoApp class represents an application that uses Cupertino design • It implements the current iOS design language based on Apple's Human Interface Guidelines. import 'package:flutter/cupertino.dart'; void main() => runApp( CupertinoApp( title: 'Cupertino App Demo', home: CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( middle: const Text('Cupertino App Demo'), ), child: Center( child: Text('Hello Riga'), ), ) ), );
  • 31. Types of Widgets • Stateless widgets • Changing the properties of stateless widgets has no effect on the rendering of the widget • Stateful widgets • Changing the properties of stately widgets will trigger the life cycle hooks and update its UI using the new state
  • 32. Creating a Stateless Widget • To create a stateless widget: • Name the new Widget class • Extend the class from StatelessWidget • Implement the build() method, with one argument of type BuildContext and return type of Widget class MyCustomWidget extends StatelessWidget { @override Widget build(BuildContext context) { return null; } }
  • 33. Defining the Stateless Widget class MyCustomWidget extends StatelessWidget { // all properties in stateless widget must declare with final or const final String name; // class constructor MyCustomWidget(this.name); @override Widget build(BuildContext context) { return Center( child: Container( margin: const EdgeInsets.all(10.0), color: Color(0xFFFFBF00), width: 300.0, height: 100.0, child: Center( child: Text( 'Hello, $name!', textDirection: TextDirection.ltr, style: TextStyle( color: Color(0xFF000000), fontSize: 32, ) ), ), ), ); } }
  • 34. Using the Stateless Widget void main() => runApp( Directionality( textDirection: TextDirection.ltr, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'Hello, world!', ), MyCustomWidget("Riga"), ], ), ), ), );
  • 35. Using the Stateless Widget void main() => runApp( Directionality( textDirection: TextDirection.ltr, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'Hello, world!', ), MyCustomWidget("Riga"), MyCustomWidget("Singapore"), ], ), ), ), );
  • 36. Hot Reload@override Widget build(BuildContext context) { return Center( child: Container( margin: const EdgeInsets.all(10.0), color: Color(0xFFFFBF00), width: 300.0, height: 100.0, child: Center( child:Text( 'Welcome!, $name!', textDirection: TextDirection.ltr, style:TextStyle( color: Color(0xFF000000), fontSize:32, ) ), ), ), ); }
  • 37. class MyCustomStatefulWidget extends StatefulWidget { MyCustomStatefulWidget({Key key, this.country}) : super(key: key); final String country; @override _DisplayState createState() => _DisplayState(); } class _DisplayState extends State<MyCustomStatefulWidget> { int counter = 0; @override Widget build(BuildContext context) { return Center( ... ); } } Stateful Widgets Doesn’t contain state or UI representation Contains the state and UI • Stateful widgets do not exist by themselves; they require an extra class to store the state of the widget
  • 38. class _DisplayState extends State<MyCustomStatefulWidget> { int counter = 0; @override Widget build(BuildContext context) { return Center( child: Container( margin: const EdgeInsets.all(10.0), color: Color(0xFFFFBF00), width: 300.0, height: 100.0, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ ... ], ), ), ) ); } }
  • 39. ... children: <Widget>[ Text( widget.country, textDirection: TextDirection.ltr, style:TextStyle( color: Color(0xFF000000), fontSize:32, ) ), Center( child: GestureDetector( onTap: () { setState(() { ++counter; }); }, child: Container( decoration: BoxDecoration( shape: BoxShape.rectangle, color: Color(0xFF17A2B8), ), child: Center( child: Text( '$counter', style: TextStyle(fontSize: 25.0), ), ), ), ), ), ], ...
  • 40. Using the Stateful Widget import 'package:flutter/material.dart'; void main() => runApp( Directionality( textDirection: TextDirection.ltr, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'Hello, world!', ), MyCustomStatefulWidget(country: "Riga"), MyCustomStatefulWidget(country: "Singapore"), ], ), ), ), );
  • 41. GestureDetector Center( child: GestureDetector( onTap: () { setState(() { ++counter; }); }, onLongPress: () { setState(() { --counter; }); }, child: Container( … • The GestureDetector widget doesn’t have a visual representation but instead detects gestures made by the user • When the user taps the Container, the GestureDetector calls its onTap callback • You can use GestureDetector to detect a variety of input gestures, including taps, drags, and scales.
  • 42. Using the Stateful Widget in a Material App void main() => runApp( MaterialApp( title: 'Material App Demo', home: Scaffold( appBar: AppBar( title: Text('Material App Demo'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'Hello, world!', ), MyCustomStatefulWidget(country: "Riga"), MyCustomStatefulWidget(country: "Singapore"), ], ), ), ), ) );
  • 43. Combining Stateless and Stateful Widgets void main() => runApp( MaterialApp( title: 'Material App Demo', home: Scaffold( appBar: AppBar( title: Text('Material App Demo'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'Hello, world!', ), MyCustomStatefulWidget(country: "Riga"), MyCustomStatefulWidget(country: "Singapore"), MyCustomWidget("Latvia"), ], ), ), ), ) );
  • 44. Packages • Flutter supports using shared packages contributed by other developers • Some commonly used packages: • http • location • google_maps_flutter • flutter_local_notifications
  • 45. Demos