Today 요약
[✅] 프로그래머스 lv0 2문제
[✅] flutter 강의 4개
배운점
1) js BigInt
- number 원시 값이 안정적으로 나타낼 수 있는 최대치인 2^53-1 보다 큰 정수를 표현
- Number와 차이점 Math 객체의 메서드와 사용할 수 없고 Number와 혼합해 사용할 수 없다
BigInt - JavaScript | MDN
BigInt 는 Number 원시 값이 안정적으로 나타낼 수 있는 최대치인 2^53 - 1보다 큰 정수를 표현할 수 있는 내장 객체입니다.
developer.mozilla.org
const theBiggestInt = 9007199254740991n;
const alsoHuge = BigInt(9007199254740991);
// ↪ 9007199254740991n
const hugeString = BigInt("9007199254740991");
// ↪ 9007199254740991n
const hugeHex = BigInt("0x1fffffffffffff");
// ↪ 9007199254740991n
const hugeBin = BigInt(
"0b11111111111111111111111111111111111111111111111111111",
);
// ↪ 9007199254740991n
2) flutter Navigation
void _onTap(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute(
builder : (context) => const LoginScreen(),
)
)
}
3) flutter push await
- push는 Future를 return하므로 결과를 awit 할 수 있다
Return data from a screen
How to return data from a new screen.
docs.flutter.dev
void _onTap1(BuildContext context) {
Navigator.of(context).pop("hi~");
}
void _onTap2(BuildContext context) async {
final result = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const NextScreen(),
),
);
print(result); //"hi~"
}
3) flutter PageRouteBuilder
- page route에 animation, duration 등을 설정할 수 있게 해주는 위젯
Animate a page route transition
How to animate from one page to another.
docs.flutter.dev
void _onTap(BuildContext context) {
Navigator.of(context).push(
PageRouteBuilder(
transitionDuration : Duration(seconds:1),
reverseTransitionDuration: Duration(seconds:1),
pageBuilder:((context, animation, secondaryAnimation) => NextScreen()),
transitionsBuilder :(context, animation, secondaryAnimation, child) {
final offsetAnimation = Tween (
begin : Offset(0,-1),
end : Offset.zero,
).animate(animation);
return SlideTransition(
position:offsetAnimation,
child:FadeTransition(
opacity : animation,
child:child,
)
)
}
)
)
}
4) flutter Tween
- AnimationController 개체의 범위는 0.0에서 1.0이다
AnimationController controller = AnimationController(
duration: const Duration(milliseconds: 500), vsync: this);
Animation<int> alpha = IntTween(begin: 0, end: 255).animate(controller);
5) flutter pushNamed
- 앱의 여러 부분에서 동일한 화면으로 이동해야 하는 경우 코드가 중복될 수 있어 이름 경로로 정의하고 탐색 한다
Navigate with named routes
How to implement named routes for navigating between screens.
docs.flutter.dev
- 5-1 : 화면 2개 만들기
import 'package:flutter/material.dart';
class FirstScreen extends StatelessWidget {
const FirstScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('First Screen'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
// Navigate to the second screen when tapped.
},
child: const Text('Launch screen'),
),
),
);
}
}
class SecondScreen extends StatelessWidget {
const SecondScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
// Navigate back to first screen when tapped.
},
child: const Text('Go back!'),
),
),
);
}
}
- 5-2 경로 정의
- initialRoute : 앱이 시작되어야 하는 경로를 정의, 이 routes 속성은 사용 가능한 명명된 경로와 해당 경로로 이동할 때 빌드할 위젯을 정의한다
MaterialApp(
title: 'Named Routes Demo',
// Start the app with the "/" named route. In this case, the app starts
// on the FirstScreen widget.
initialRoute: '/',
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/': (context) => const FirstScreen(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/second': (context) => const SecondScreen(),
},
)
- 5-3 화면이동
// Within the `FirstScreen` widget
onPressed: () {
// Navigate to the second screen using a named route.
Navigator.pushNamed(context, '/second');
}
번외 name 명을 오타날 수 있으니 해당 스크린에서 수정할 수도 있다
MaterialApp(
title: 'Named Routes Demo',
initialRoute: FirstScreen.routeName,
routes: {
FirstScreen.routeName: (context) => const FirstScreen(),
SecondScreen.routeName: (context) => const SecondScreen(),
},
)
import 'package:flutter/material.dart';
class FirstScreen extends StatelessWidget {
const FirstScreen({super.key});
static String routeName = "/firstscreen";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('First Screen'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
// Navigate to the second screen when tapped.
},
child: const Text('Launch screen'),
),
),
);
}
}
class SecondScreen extends StatelessWidget {
const SecondScreen({super.key});
static String routeName = "/secondscreen";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
// Navigate back to first screen when tapped.
},
child: const Text('Go back!'),
),
),
);
}
}
주절주절
- 정신없는 월요일.. 정신없는 공부..!
'TIL' 카테고리의 다른 글
| 20230901 TIL : 9월도 뿌시기 (0) | 2023.09.01 |
|---|---|
| 20230830 TIL : 급할수록 천천히 기초다지기 (0) | 2023.08.30 |
| 20230826 TIL (1) | 2023.08.26 |
| 20230823 TIL (1) | 2023.08.23 |
| 20230822 TIL (0) | 2023.08.22 |