๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์›น๊ณต๋ทฐ/flutter

flutter ํ”Œ๋Ÿฌํ„ฐ ํŒŒ์ด์–ด๋ฒ ์ด์Šค ์ดˆ๊ธฐ ์„ธํŒ…

by ์ด๋…ธํ‚ค_ 2023. 6. 26.

 

1. ์šฐ์„  ํ”Œ๋Ÿฌํ„ฐ ํ”„๋กœ์ ํŠธ๋Š” ๋งŒ๋“ค์–ด ๋†“์€ ์ƒํƒœ์ž„

2. ํŒŒ์ด์–ด๋ฒ ์ด์Šค ํ”„๋กœ์ ํŠธ๋„ ํ•˜๋‚˜ ํŒŒ๋†“์Œ

3. ํŒŒ์ด์–ด๋ฒ ์ด์Šค ์ฝ˜์†”๋กœ ์ด๋™ํ•ด์„œ flutter ํ”„๋กœ์ ํŠธ ์‹œ์ž‘ํ•˜๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ

3.1 ์ž‘์—…๊ณต๊ฐ„ ์ค€๋น„๋Š” ๋๋‚ด๋†“์Œ

 

 

3.2 flutterfire cli ์„ค์น˜ ๋ฐ ์‹คํ–‰๋„ ์™„๋ฃŒ

4. ํ”„๋กœ์ ํŠธ ํด๋” lib/firebase_options.dart ํŒŒ์ผ ์ƒ์„ฑ๋œ๊ฒƒ์„ ํ™•์ธ

- ๋‹ค๋งŒ ๋‚ด๋ถ€์ ์œผ๋กœ firebase_core ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์—†์–ด์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์žˆ๋Š” ์ƒํƒœ์ž„

 

5. firebase_core ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€

flutter pub add firebase_core

- ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ถ”๊ฐ€๋˜๋ฉด์„œ ์˜ค๋ฅ˜ ์‚ฌ๋ผ์ง

 

6. main.dart ํŒŒ์ผ์—  ์•„๋ž˜ ๋‚ด์šฉ ์ž…๋ ฅ

import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

import 'package:flutter/material.dart';
import 'package:uddutsi/tab/tab_page.dart';

void main() async{

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  runApp(const MyApp());
}

7. ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋œฌ๋‹ค. 

3๋ฒˆ์งธ ๋ผ์ธ์˜ WidgetsFlutterBinding.ensureInitialized() ๋ฅผ  firebase ์ฝ”๋“œ ์‹คํ–‰์ „์— callํ•œ๋‹ค.

E/flutter (31343): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Binding has not yet been initialized.
E/flutter (31343): The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
E/flutter (31343): Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After calling that method, the "instance" getter will return the binding.
E/flutter (31343): In a test, one can call "TestWidgetsFlutterBinding.ensureInitialized()" as the first line in the test's "main()" method to initialize the binding.
E/flutter (31343): If ServicesBinding is a custom binding mixin, there must also be a custom binding class, like WidgetsFlutterBinding, but that mixes in the selected binding, and that is the class that must be constructed before using the "instance" getter.
void main() async{

  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  
  runApp(const MyApp());
}

 

8. ํ”„๋กœ์ ํŠธ๊ฐ€ ์ž˜ ์‹คํ–‰๋จ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

๋Œ“๊ธ€