Flutter
[Flutter] 코딩셰프 순한맛 2-1 온보딩 스크린 만들기
건물주개발자
2024. 10. 4. 01:22
- flutter 패키지인 introduction_screen 버전을 추가하고 pub get
- introduction_screen에 들어갈 이미지 파일들이 있는 image 디렉토리를 asset 속성에 추가
name: flutter_practice
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ^3.5.1
dependencies:
http: ^1.2.2
flutter:
sdk: flutter
cupertino_icons: ^1.0.8
fluttertoast: ^8.2.8
introduction_screen: ^3.1.14
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^4.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
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:
- image/
//main.dart
import 'package:flutter/material.dart';
import 'onboarding.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: OnBoardingPage(),
);
}
}
class MyPage extends StatelessWidget {
const MyPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Main page'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Main Screen',
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const OnBoardingPage()),
);
},
child: const Text('Go to onboarding screen'),
),
],
),
),
);
}
}
//onboarding.dart
import 'package:flutter/material.dart';
import 'package:flutter_practice/main.dart';
import 'package:introduction_screen/introduction_screen.dart';
class OnBoardingPage extends StatelessWidget {
const OnBoardingPage({super.key});
@override
Widget build(BuildContext context) {
return IntroductionScreen(
pages: [
PageViewModel(
title: 'Welcome to my app',
body: 'This is the first page'
'We are making on-boarding screens',
image: Image.asset('image/page1.png'),
decoration: getPageDecoration()),
PageViewModel(
title: 'Welcome to my app',
body: 'This is the second page',
image: Image.asset('image/page2.png'),
decoration: getPageDecoration()),
PageViewModel(
title: 'Welcome to my app',
body: 'This is the third page',
image: Image.asset('image/page3.png'),
decoration: getPageDecoration()),
],
done: const Text('done'),
onDone: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const MyPage()),
);
},
next: const Icon(Icons.arrow_forward),
showSkipButton: true,
skip: const Text('skip'),
dotsDecorator: DotsDecorator(
color: Colors.cyan,
size: const Size(10,10),
activeSize: const Size(22, 10),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24)
),
activeColor: Colors.red
),
curve: Curves.bounceOut,
);
}
}
PageDecoration getPageDecoration() {
return const PageDecoration(
titleTextStyle: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
bodyTextStyle: TextStyle(fontSize: 18, color: Colors.blue),
imagePadding: EdgeInsets.only(top: 40),
pageColor: Colors.orange);
}
https://pub.dev/packages/introduction_screen
introduction_screen | Flutter package
Introduction/Onboarding package for flutter app with some customizations possibilities
pub.dev