Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Created August 4, 2021 06:03
Show Gist options
  • Save doyle-flutter/fab8622bdb3314215e5faad4befd471b to your computer and use it in GitHub Desktop.
Save doyle-flutter/fab8622bdb3314215e5faad4befd471b to your computer and use it in GitHub Desktop.
행안부 주소 검색 OPEN API - Flutter
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
/// [pub] webview_flutter: ^2.0.10 : https://pub.dev/packages/webview_flutter
void main() => runApp(Sys());
class Sys extends StatelessWidget {
const Sys({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(home: Main());
}
}
class Main extends StatefulWidget {
const Main({Key? key}) : super(key: key);
@override
_MainState createState() => _MainState();
}
class _MainState extends State<Main> {
String? title;
@override
void initState() {
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
padding: EdgeInsets.all(10.0),
child: Text(this.title ?? "검색 내용이 없습니다")
),
TextButton(
child: Text("검색"),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context){
final String _key = "발급받은 키를 넣어주세요";
final String _url = "http://NODEJS IP를 넣어주세요:3000";
return Scaffold(
body: SafeArea(
child: WebView(
initialUrl: "https://www.juso.go.kr/addrlink/addrMobileLinkUrl.do?confmKey=$_key&returnUrl=$_url",
javascriptMode: JavascriptMode.unrestricted,
javascriptChannels: {
JavascriptChannel(name:'james', onMessageReceived: (JavascriptMessage msg){
setState(() => this.title = msg.message);
Navigator.of(context).pop();
})
},
),
),
);
}
)
),
),
],
),
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment