flutter- Admob 배너 적용.

flutter에 Admob 배너 적용하는 방법. * 라이브러리 페이지. https://pub.dev/packages/google_mobile_ads * Admob 라이브러리 설치. flutter pub add google_mobile_ads * AndroidManifest에 추가. 인터넷 권한은 admob 라이브러리에서 자동병합 되어 따로 할 필요가 없다. android\app\src\main\AndroidManifest.xml <application>        <meta-data            android:name="com.google.android.gms.ads.APPLICATION_ID"            android:value="ca-app-pub-##############"/> </application> * build.gradle에 추가.  2022년08월 현재 flutter과 Admob이 minSdkVersion 불일치로 컴파일 에러가 난다. minSdkVersion 19, 20 가능하지만 추가 코드 작업이 필요하다. 특별한 사유가 없으면 21로 하는 걸 추천한다. android\app\build.gradle minSdkVersion 21 * Admob 라이브러리 초기화. main.dart 이나 초기화 코드에 아래 코드를 넣는다.   MobileAds.instance.initialize(); * 구현 코드.  본인에 맞게 변경해 구현한다. // 광고 ID 를 리턴하는 함수 . String getAdId () { if (!kReleaseMode) { return 'ca-app-pub-3940256099942544/6300978111' ; } if (Platform.isAndroid) { return 'ca-app-pub-#############' ; } else if (Platform.isIOS) { //

flutter - flutter_native_splash 스플래시 이미지 추가.

flutter 실행시 네이티브에서 플러터를 로딩하는 시간에 지연이 있다. 하얀 화면보다 스플래시 이미지를 보는게 유저가 느끼는 경험이 더 좋다.   flutter_native_splash를 이용하면 코드 작업 없이 스플래시 적용할 수 있다. 물론 따로 처리해야 하는 것도 가능하다. * 라이브러리 페이지. https://pub.dev/packages/flutter_native_splash * 라이브러리 설치. flutter pub add flutter_native_splash * pubspec.yaml 에 추가. 각자 환경에 맞게 세팅하면 된다. # flutter pub run flutter_native_splash:remove # flutter pub run flutter_native_splash:create flutter_native_splash : color : "#3B303E" image : assets/image/splash_logo.png fullscreen : true android_12 : color : "#3B303E" image : assets/image/splash_logo12.png # branding: assets/image/splash_logo.png * 터미널에서 실행한다.(Android Studio 터미널도 가능하다.) flutter pub run flutter_native_splash:create - 여기까지 하면 적용 완료다. 에뮬레이터에서는 확인할 수 없다. 진짜 핸드폰에 설치해 확인할 수 있다. * 만약 설정이 바뀌거나 스플래시 이미지가 바뀐 경우는 remove 후 create 해주면 된다. flutter pub run flutter_native_splash:remove flutter pub run flutter_native_splash:create - 주의. 에뮬레이터에서는 스플래시 이미지 적용이 원할하지 않았다.  핸드폰을 꼽았을 때는 제대로 확인이 됐습

flutter 방향 고정. 가로, 세로.

아래 한 줄이면 어플의 방향을 고정할 수 있습니다. SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); 방향 옵션 입니다.. enum DeviceOrientation { portraitUp , landscapeLeft , portraitDown , landscapeRight , }

flutter license 표시 페이지.

손쉽게 어플에서 표시할 라이센스를 표시합니다.. pubspec.yaml 파일 dependencies 에 추가한 라이브러리도 자동으로 표시합니다. 아래 한 줄만 넣으면 됩니다. Navigator.of(context).push(MaterialPageRoute(builder: (_) => const LicensePage())); 만약 수동으로 추가한 추가 라이센스가 있다면 아래와 같이 추가할 수 있습니다. void licenseAdd () { LicenseRegistry. addLicense (() => Stream <LicenseEntry>. value ( const LicenseEntryWithLineBreaks ( <String>[ '라이브러리 이름' ] , ''' 라이센스 본문을 복사한다. ''' , ) , )) ; }

dart (flutter) 문법 - 생성자.

플러터는 생성자의 구문이 매우 다양 합니다. https://dartpad.dev 에 아래 코드를 복사해서 실행해 보세요. factory 는 다음 페이지에 정리되어 있습니다. https://abel9999.blogspot.com/2022/07/dart-flutter-factory.html class Animal { String name = '' ; int id = 0 ; // 이름 없는 생성자 . Animal() {} // 이름 없는 생성자는 하나이상 만들수 없다 . // Animal(int i) { } // 에러 . // 이름 있는 생성자 . Animal. name () {} // 생성자를 여러개 만들수 있고 // 멤버변수의 기본값을 설정할 수 있다 . Animal. nameNew () : name = 'test' {} // 생성자에서 파라메터를 받을수 있다 . // 아래 생성자는 동일한 동작을 한다 . Animal. arg (String n) { name = n ; } Animal. arg2 (String n) : name = n {} Animal. arg3 ( this . name ) ; // {} 로 둘러산 부분은 호출시에 이름을 지명해야 한다 . // 예 ) Animal a = Animal.argName(name:'go', id:2); Animal. argName ({ required this . name , required this . id }) ; // [] 로 둘러싼 부분은 호출시에 값이 없으면 기본값을 지정한다 . // 예 ) // Animal a = Animal.argName2(); // Animal a2 = Animal.argName2('go'); // Animal a3 = Animal.argName2('go'. 33); // Animal a4 = Animal.argName

dart (flutter) 문법 - null 관련 문법 정리.

dart문법에서 아래 키워드를 코드와 주석으로 설명 합니다. ?  !  ??  ??=  ?.  ?.. https://dartpad.dev 에 아래 코드를 복사해서 실행해 보세요. void main () { String? strTest ; // '?' 는 null 이 가능하다는 표시 . // '!' 는 strTest 가 null 이 아니라는 표시 . // Uncaught TypeError 예외가 난다 . //print("'!' $strTest!"); print(strTest) ; // null 을 print 하면 null 출력한다 . strTest = "test" ; print(strTest) ; // getString() {} 은 null 을 리턴할 수 있다는 암시적 표현이다 . print( "'getString()' ${getString()} " ) ; // String? getString2() {} 은 null 을 리턴할 수 있다는 명시적 표현이다 . print( "'String? getString2()' ${getString2()} " ) ; // String getString3() {} 은 반드시 String 을 리턴하는 명시적 표현으로 // return "test" 가 없으므로 예외가 난다 . int? nInt ; int res = nInt ?? 5 ; // '??' 는 nInt 가 null 이면 5 를 반환한다 . print( "'??' $res " ) ; nInt ??= 5 ; // '??=' 는 nInt 가 null 이면 nInt 에 5 를 할당한다 . print( "'??=' = $res " ) ;

android studio emulator만 독립 실행하는 방법.

안드로이드 개발할 때 사용하는 에뮬레이터를 독립 실행하는 방법입니다. 안드로이드 스튜디오 실행 없이 에뮬레이터를 사용하고 싶거나, 빠르게 에뮬레이터를 실행하고 싶을 때 사용 합니다. https://developer.android.com/studio 안드로이드 스튜디오를 설치하고 안드로이드 스튜디오에 있는 디바이스 매니저로 가상 디바이스를 만듭니다. https://www.nirsoft.net/utils/nircmd.html 다운 받아 압축을 풀고 nircmd 파일을 아래 배치 파일과 같은 경로에 복사 합니다. 배치파일을 실행하면 검은 콘솔이 같이 뜨는데 콘솔을 보이지 않게 해 줍니다. 아래 스크립트를 콘솔(cmd.exe)에서 실행하거나 배치파일(bat)을 만들어 실행하면 됩니다. bat로 만드는게 더 편합니다. * 에뮬레이터에 생성된 가상 디바이스 목록을 보여줍니다. %localappdata%\Android\Sdk\emulator\emulator -list-avds @pause * 에뮬레이터를 실행합니다. nircmd exec hide %localappdata%\Android\Sdk\emulator\emulator -avd <디바이스이름> 위 경로는 sdk가 설치되어 있는 기본 경로 입니다. 다른 폴더에 설치했다면 경로를 변경해 줘야 합니다.