Created
February 18, 2021 08:57
-
-
Save doyle-flutter/4ba8eed5f96adadee533c2c805425b21 to your computer and use it in GitHub Desktop.
#06 백그라운드 - 플러터
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... import 생략 | |
| class IntentService extends StatefulWidget { | |
| @override | |
| _IntentServiceState createState() => _IntentServiceState(); | |
| } | |
| class _IntentServiceState extends State<IntentService> { | |
| String data; | |
| MethodChannel dataChannel; | |
| @override | |
| void initState() { | |
| dataChannel = new MethodChannel("app.james.cam/backdata") | |
| ..setMethodCallHandler((call) { | |
| print(call.method); | |
| print(call.arguments.toString()); | |
| if (call.method == "data") { | |
| if(!mounted) return; | |
| setState(() { | |
| this.data = call.arguments; | |
| }); | |
| } | |
| return; | |
| }); | |
| super.initState(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar(title: Text(this.data ?? "IntentService with Flutter"),), | |
| body: Center( | |
| child: TextButton( | |
| child: Text("Play"), | |
| onPressed: () async{ | |
| const String _method = "intentservicestart"; | |
| const String _channelName = "app.james.cam/intentservice"; | |
| MethodChannel channel = new MethodChannel(_channelName); | |
| await channel.invokeMethod<void>(_method); | |
| return; | |
| }, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment