반응형
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
반응형
'📱Mobile > 🔥Flutter' 카테고리의 다른 글
[Flutter] 기초가 되는 StreamBuilder BLOC 패턴, StreamSubscription, yield example (0) | 2021.01.06 |
---|---|
[Flutter] Cubit를 사용한 BLOC 패턴, Bloc.observer example (0) | 2021.01.04 |
[Flutter] fluro package (navigation 이동, route, transition) sample code (0) | 2020.12.22 |
[Flutter] Flutter 플랫폼 채널을 이용해서 Android 코드 호출하기 (MethodChannel) (0) | 2020.10.25 |
[Flutter] Flutter 생명주기 Sample Code (0) | 2020.10.25 |