본문 바로가기
📱Mobile/🔥Flutter

[Flutter] flutter intro(splash) -> login page timer sample code

by 후누스 토르발즈 2020. 10. 26.
반응형

flutter_example/widgets 패키지를 하나 만듭니다.

 

 

 

main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_example/widgets/introPage.dart';
import 'package:flutter_example/widgets/loginPage.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      home: IntroPage(),
      routes: {
        IntroPage.IntroPageRouteName: (context) => IntroPage(),
        LoginPage.LoginPageRouteName: (context) => LoginPage(),
      },
    );
  }
}

 

 

 

introPage.dart

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'loginPage.dart';

class IntroPage extends StatefulWidget {
  static const IntroPageRouteName = '/IntroPage';

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

class _IntroPageState extends State<IntroPage> {

  @override
  void initState() {
    super.initState();
    Timer(Duration(seconds: 3), () {
      Navigator.pushNamed(context, LoginPage.LoginPageRouteName,);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: Container(
          child: Image.asset('assets/flutter_logo.png'),
          width: 200,
        ),
      ),
    );
  }
}

 

 

loginPage.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class LoginPage extends StatefulWidget {
  static const LoginPageRouteName = '/LoginPage';

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

class _LoginPageState extends State<LoginPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:Container(
        child: Center(
          child:Text('로그인화면'),
        ),
      )
    );
  }
}

 

assets 폴더 하나 만듭니다.

flutter_example/assets/flutter_logo.png 

 

pubspec.yaml

 

  assets:
    - assets/

 

추가시에 열을 잘 맞추어야합니다. 오류를 낼수 있습니다.

 

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
반응형