Flutter

[Flutter] kakao 주소 검색 (kopo)

KOPO 패키지 주소, GET 패키지 주소

Flutter pubspec.yaml 파일에 코드 추가

dependencies:
  kopo: ^0.1.3
  get: ^3.24.0

Kopo 코드 정리

/// 카카오 주소 검색 이동
Get.to(Kopo());
/// 이동 및 결과값 가져오기 #return Type KopoModel
KopoModel model = await Get.to(Kopo());

/// 결과값
print("검색 주소 : ${model.address}");
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kopo/kopo.dart';

class DaumAddressSearch extends StatefulWidget {
  String title;
  DaumAddressSearch({this.title});

  @override
  _DaumAddressSearchState createState() => _DaumAddressSearchState();
}

class _DaumAddressSearchState extends State<DaumAddressSearch> {

  String address;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    address = "";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("${widget.title}"),
        centerTitle: true,
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            alignment: Alignment.center,
            height: 60,
            margin: EdgeInsets.fromLTRB(10, 0, 10, 0),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(5),
              border: Border.all(width: 1),
            ),
            child: FlatButton(
              height: 60,
              minWidth: double.infinity,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(5),
              ),
              child: Text("주소 검색", textAlign: TextAlign.center,),
              onPressed: () async{
                KopoModel model = await Get.to(Kopo());
                print("검색 주소 : ${model.address}");
                setState(() {
                  this.address = model.address;
                });
              },
            ),
          ),
          Container(
            margin: EdgeInsets.fromLTRB(5, 10, 5, 0),
            alignment: Alignment.center,
            child: Text("주소 결과 : $address", textAlign: TextAlign.center, style: TextStyle(fontWeight: FontWeight.bold),),
          )
        ],
      )
    );
  }
}

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다