4-6.(p.54)lib/main.dart


lib/main.dart

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:photoapp/photo_list_screen.dart';
import 'package:photoapp/sign_in_screen.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Photo App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      // ログイン状態に応じて表示する画面を切り替える
      home: FirebaseAuth.instance.currentUser == null
          ? SignInScreen()
          : PhotoListScreen(),
    );
  }
}