플러터에서 date picker를 기본 제공해 주고 있다.

정확히 말하면 flutter/material.dart에 showDatePicker함수가 

datepicker를 구현한다.

 

아래는 플러터사이트의 튜터리얼에 있는 사용법이다.

Future<DateTime> selectedDate = showDatePicker(
  context: context,
  initialDate: DateTime.now(),
  firstDate: DateTime(2018),
  lastDate: DateTime(2030),
  builder: (BuildContext context, Widget child) {
    return Theme(
      data: ThemeData.dark(),
      child: child,
    );
  },
);

 

이를 조금더 사용하기 쉽게 사용자 함수로 아래와 같이 만들었다.

return 값을 받는게 목적이다.

  Future selectDate() async {
    DateTime picked = await showDatePicker(
        context: context,
        locale: const Locale('ko', 'KO'),
        initialDate: DateTime.now(),
        firstDate: DateTime(2015),
        lastDate: DateTime(2030),
        builder: (BuildContext context, Widget child) {
          return Theme(
            data: ThemeData.dark(),
            child: child,
          );
        },
    );
    if(picked != null) {
      return picked.toString().substring(0, 10 );
    } else {
      return null;
    }
  }

 

버튼에 이벤트를 달아 실행하니

아래와 같은 에러가 발생했다.

 

 

 

에러 문구

The following NoSuchMethodError was thrown building Directionality(textDirection: ltr):
The method 'formatFullDate' was called on null.
Receiver: null
Tried calling: formatFullDate(Instance of 'DateTime')

 

formatFullDate라는 함수를 호출하면서 null 에러가 발생한것이다.

 

구글링 결과

국제 지역화 정보를 사용한다는 것을 셋팅하여야 한다는 것이다.

 

첫번째는 pubspec.yaml에서 페키지를 dependency 하고

main.dart에서 MateralApp에 localizationsDelegates 와 supportedLocales를 설정해 주면된다.

 

pubspec.yaml

  # lcalizations package
  flutter_localizations:
    sdk: flutter

 

main.dart

      child: MaterialApp(
          title: 'TEST APP',
          localizationsDelegates: [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
          ],
          supportedLocales: [
            const Locale('en', 'US'),
            const Locale('ko', 'KO'),
          ],

 

에뮬레이터 재시작을 하니 아주 예쁘게 달력이 출력된다.

 

 

테스트 결과 supportedLocales는 설정하지 않아도 달력이 정상적으로 출력된다.

한가지 아쉬운것은 달만 선택가능하는 기능을 제공하지 않는것이다.

 

플러터에서 base64 문자열을 이미지로 표현하는 방식이다.

 

 

String base64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQYAAADBCAMAAAAace62AAAAyVBMVEX////y8vP7+/v8/Pz29vfQz9FdXV/v7/BPT1D///7X1thKSkvu7u/k5OV+fYBZWVtsbG5jY2V0c3ZBQEKQj5K/vsDo6OnHxsm4t7lHR0g9PT6gn6KamZsAAACqqayUk5eCgoQ4NzixsLQ/ODorKSo0MjMsJyhoZ2kjIB8sJyQzLSs5NDVER0aJiIxVU1Td3N4dGhkXFRIjGholJiM5My8yLycoIRwkIBQcHBY2LjEXFQ4bGRsVFBYiICIeFxRMRUczJSgRDgElLCndRnHNAAAQMklEQVR4nO2d6WKjuJaADQZZFwESEhgQBCMbjDcg6WR6Kl2Vyu15/4canM14S9vY2Tp8f7qLOLI40ll1IJ1OS0tLS0tLS0sj5I+eQEtLy9ugG616dzoaAVErBxdbBKkfPYuPRrMsCxHpo6fxwahWTJCIPnoaH4w8sClitPcGQ3ffYMy3Qs1Njqzyo6fxwfQGtEDwu6uEbmeoAM5X2r5vQYA4t+h3jxk0NrpDpP/R0/hgFHOeJPi7m8dOLApBtI+exUejMcyx/tGz+GhKxhAyPnoWH02fpovJekL1Df2mCgSH9tolJ3S/myD6mZ/CQT2tVE0A2TcLJx0COStqKtENMmDBCT1pVNnQv1K+LgW+BQSrq0RECMTFpXnSuG6Rmc6XEUTPziyL8Vr0KIeVFFJSJMOTBtYDQvn9F6ljKUMICIBj9+WKZFOrwGoOrzbE0B8eF2iXOU595Jxjlm+OlgEC/RlZeYWBBXxqSBZjayGl7MTwyFtSSjKf/fEVDO3QsohjjfjLHSsRhay63T6chPUP9lUTeUd7UMWbzsafPkCXA4yLyGHjF2PYDc1sWYrseiKpq7VKM9RoWaPpdP5OwWkZDJUmvyfnBcxUmY5WCza0Y99cVhyiBK0+qAwAyxrmnvb0z3cqYUSQNDLIQZHBYUdl4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wAPP2HG/17oFBCQgcKMPt2B0XuiRKQgWei9xd+A+UrIpaF/qjiupaXlK9H97ja02+loahDS0DO+cXi1fIXp/3EkCoulPP6EpwnvhGRiAdOUc1BkbPRd//6kCnhBHVdV1LAQ82kKvqVm6Gjx3P0p9x1xOfYP7Cf/VyGZENWOmg36U/jZ/o/v4/O1sRyHQRZx/d+yhwn7fklYiAYbCYdmkui75SCSsKokdP1aHsLvth007vQ3m108Gn+Rv/JyLgxaDOHcXi/ZB+bhD/H/O/AQJbPf0bqdjwGVzvHG0q9DZAZ4+udaUqUEBH3CZq03xY3VP6aifkWxLXziS2a/HrphkPFk1cCmGLbA1nfzE51l9+qlYE9vzuvpsY99/M3cxCPuj8XkrxRnJCsEStnsjB0gXwogfk2u04lI/eQa5853CyCf6S4Pu5Mkvf6Z2N8sXthAMUotitxvaBpbWlpaWlrenq9eh21paWlpaWlpaWlpaXl32kTqPfg6Uv46M21paWn50sitvW1paWlpaWlpaWlpaWlpaWlpaWlpaWlp+Xfx/x0QSFYtvZRLAAAAAElFTkSuQmCC';

 

기존에는 

 

Image.memory(base64Decode(base64))

 

dart가 업데이트 된 이후인지 몰라도 해당 아래와 같이 코드가 오류가 발생했다.

Invalid character (at character 5)
data:image/png;base64,

 

아래와 같이 소스를 수정하여 에러를 수정했지만, 

 

Image.memory(Uri.parse(base64).data.contentAsBytes())

 

일시적인 오류인지 원인은 아직 파악을 하지 못했다.

 

Flutter 작업을 하면서 이런 저런 문제를 해결 하는 재미도 쏠쏠하다.

 

플러트 프로젝트를 깃허브에서 가져와서 비주얼스튜디오 코드로 열면

처음에는 엑박이 뜨는 경우가 있습니다.

플러터 프로젝트에서 쓰는 라이브러리가 없기 때문인데요.

 

 

해결 방법은

cmd 창에서

flutter packages get

명령을 실행하면 아래와 같이 필요한 라이브러리를 가져옵니다.

 

 

또는 라이브러리가 선언된 파일인

pubspec.yaml 파일을 열고

마우스 오른쪽  버튼을 클릭하여

Get Packages 메뉴를 클릭하면 라이브러리를 가져오게 됩니다.

 

 

 

+ Recent posts