Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Flutter communicate with Native code (iOS, Andr...
Search
word
July 27, 2019
0
130
Flutter communicate with Native code (iOS, Android)
Agenda
- About Flutter
- Flutter Platform Channel
- Demo
- Q & A
word
July 27, 2019
Tweet
Share
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
A better future with KSS
kneath
239
18k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
2.9k
BBQ
matthewcrist
89
9.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
KATA
mclloyd
PRO
32
15k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Transcript
'MVUUFSীࢲ/BUJWF J04 "OESPJE ٘৬ాनೞӝ ੋࣻ
*OUSPEVDF അ) Woowahan Bros. / Baemin Market Mobile platform Development
HydaiCapital / Mobile Platform Development SOCAR Mobile Developer / Mobile , Tablet DreamPlus with Hanwha S&C / ZUMO Application Lassoh inc. (Toronto in Canada) / Mobile SNS platform Samsung Mobile Group / ѓ۟द दܻૉ ѐߊ.
"HFOEB "CPVU'MVUUFS 'MVUUFS1MBUGPSN$IBOOFM %FNP 2"
"CPVU'MVUUFS Flutter is Google's mobile UI framework
"CPVU'MVUUFS 'MVUUFSJTBDSPTTQMBUGPSNNPCJMF4%,
Flutter
Fast Beautiful Open Productive Flutter
Fast Beautiful Open Productive Flutter
/BUJWF1FSGPSNBODF
Fast Beautiful Open Productive Flutter
&YQSFTTJWFBOE'MFYJCMF6*
Fast Beautiful Open Productive Flutter
'BTUEFWFMPQNFOU
Fast Beautiful Open Productive Flutter
'SFFBOEPQFOTPVSDF
'MVUUFS)JTUPSZ "OOPVODJOH'MVUUFS $VSSFOU7FSTJPO v1.7 The First Release "OOPVODJOH'MVUUFS3FMFBTF1SFWJFX .": 4&1
%&$ /08
None
2,366 Watch
71,268 Stars
8,432 Forks
421 Contributors
None
None
4UBDL0WFSGMPXUSFOE
4UBDL0WFSGMPXUSFOE
None
None
None
None
None
'MVUUFS4USVDUVSF Native Code Widgets, Rendering Platform Channels Canvas Events Location
Bluetooth Audio Sensors Camera Etc. Service Platform Application
'MVUUFS4USVDUVSF Native Code Widgets, Rendering Platform Channels Canvas Events Location
Bluetooth Audio Sensors Camera Etc. Service Platform Application
"CPVU'MVUUFS1MBUGPSN$IBOOFMT5ZQF .FTTBHF$IBOOFM .FUIPE$IBOOFM &WFOU$IBOOFM
8SJUFDVTUPNQMBUGPSNTQFDJGJDDPEF Use Platform Channels
1MBUGPSN$IBOOFMT0WFSWJFX
1MBUGPSN$IBOOFMT0WFSWJFX
1MBUGPSN$IBOOFMT0WFSWJFX
1MBUGPSN$IBOOFMT0WFSWJFX
"CPVU1MBUGPSN$IBOOFMT Platform channels are the gateway to accessing platform-specific code
in Flutter.
"CPVU1MBUGPSN$IBOOFMT What do I mean by platform-specific?
"CPVU1MBUGPSN$IBOOFMT Access to device inputs Secure storage (a.k.a. keychain on
iOS)
"CPVU1MBUGPSN$IBOOFMT The Basic building block for creating plugins
"CPVU1MBUGPSN$IBOOFMT MyOS Call Device State Camera Check
8IBUBCPVUQMBUGPSNTQFDJGJDDPEF Options : 1. Use Plugins 2. Write platform-specific code
6TF1MVHJOT
6TF1MVHJOT description: A new Flutter application. dependencies: core: path: ../core
flutter: sdk: flutter flutter_localizations: sdk: flutter xml: ^3.0.0 flutter_redux: ^0.5.0 intl: ^0.15.2 url_launcher: ^3.0.0 path_provider: ^0.4.0 key_value_store_flutter: ^1.0.0 .... ....
"CPVU1MBUGPSN$IBOOFMT MethodChannel class is defined inside the ‘service’ package.
import 'package:flutter/services.dart';
"CPVU1MBUGPSN$IBOOFMT /FFEUPJNQPSUUIFrBTZODsQBDLBHFUPTVQQPSUBTZOD GFBUVSFTJOPVSEBSUDPEFCBTF
import 'dart:async'; Need to import the ‘async’ package to support
async features in our dart codebase.
static const channel = const MethodChannel('tryflutter.github.io/flutter_BabyStep'); To define MethodChannel in
dart we use : Like this… You can name it anything, but the best practice is to name it domain_name/channel_name.
final response = await channel.invokeMethod(message, [optional_arguments]) You can name it
anything, but the best practice is to name it domain_name/channel_name.
Future<Null> _showDialog() async { final response = await channel.invokeMethod("showDialog", ["Called
From Flutter"]); final snackbar = new SnackBar(content: new Text(response)); Scaffold.of(context).showSnackBar(snackbar); }
Future<Null> _openNewPage() async { final response = await channel.invokeMethod("openPage", ["Hi
From Flutter"]); print(response); }
Future<Null> _requestNetwork() async { final response = await channel.invokeMethod( "request",
["https://www.thesportsdb.com/api/v1/json/1/"]); Navigator.push( context, new MaterialPageRoute( builder: (context) => new SecondRoute(data: response), ), ); }
class MainActivity : FlutterActivity() { ... }
val channel = MethodChannel(flutterView, "tryflutter.github.io/ platformchannel”)
channel.setMethodCallHandler { methodCall, result -> val args = methodCall.arguments as
List<*> val param = args.first() as String when (methodCall.method) { "openPage" -> openSecondActivity(param) "showDialog" -> showDialog(param, result) "request" -> callService(param, result) else -> return@setMethodCallHandler } }
private fun openSecondActivity(info: String) { startActivity<SecondActivity>("info" to info) }
private fun showDialog(content: String, channelResult: MethodChannel.Result) { MaterialDialog.Builder(this).title("Native Dialog").theme(Theme.LIGHT) .content(content)
.positiveText("Ok") .negativeText("Cancel") .onPositive { _, _ -> channelResult.success("Ok was clicked") } .onNegative { _, _ -> channelResult.success("Cancel was clicked") } .show() }
private fun callService(url: String, channelResult: MethodChannel.Result) { ... service.getEPLTeams().enqueue(object :
Callback<TeamResponse> { override fun onFailure(call: Call<TeamResponse>?, t: Throwable?) { channelResult.error("FAILURE", "CALL FAILED", t?.localizedMessage) } override fun onResponse(call: Call<TeamResponse>?, response: Response<TeamResponse>?) { channelResult.success(Gson().toJson(response?.body()?.teams)) } }) }
DEMO
None
Q & A
хࢎפ.