Today 요약
[✅] 프로그래머스 Lv0 1문제
[✅] flutter 강의 2개
[✅] dart 강의 3개
배운 점
1) flutter Navigation
Navigation and routing
Overview of Flutter's navigation and routing features
docs.flutter.dev
1-1 Navigation 1.0
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const SongScreen(song: song),
),
);
},
child: Text(song.name),
- 대부분의 앱에서는 named route 사용을 지양
- 버전 1은 flutter Web이 생기기 전에 만들어졌다
- 버전 1의 Navigator는 브라우저 상에서의 앞으로 가기 버튼을 지원하지 않아 앱에서만(android, ios) 사용한다면 괜찮다
- 이유 ? ios, android, web 세 개의 플랫폼에서 돌아가는 앱을 만드려면 url이 제대로 표시되어야 하는데 url을 위해 pushNamed를 사용할 수 있다 하지만 브라우저 상에서는 이 동작이 잘 작동하지 않는다
- 위와 같은 이유 때문에 GoRouter를 사용한다
1-2 pushNamed
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
'/': (context) => HomeScreen(),
'/details': (context) => DetailScreen(),
},
);
2) GoRouter
go_router | Flutter Package
A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more
pub.dev
$ flutter pub add go_router
2-0 사용 방법
main.dart
MaterialApp.router (
routerConfig : router,
)
router.dart
final router = GoRouter (
routes :[
Goroute(
path : FirstScreen.routeName,
builder: (context, state) => FirstScreen(),
),
Goroute(
path : SecondScreen.routeName,
builder : (context, state) => SecondScreen(),
)
]
)
FirstScreen.dart
Class FirstScreen extends StatelessWidget {
static const routeName = "/" ;
void _onTap (BuildContext context) async {
context.push(SecondScreen.routeName);
}
}
SecondScreen.dart
class SecondScreen extends StatelessWidget {
static String routeName = "/second";
}
2-1 context.pop
void pop<T extends Object?>([T? result])
Type: void Function([String?])
package:go_router/src/misc/extensions.dart
Pop the top page off the Navigator's page stack by calling [Navigator.pop].
2-2 context.go 메서드
- 사용자를 다른 화면으로 보내주는데 stack에 관련된 것은 전부 무시한다 ex) screen stack , anvigation stack 등
- route stack에 관계없이 별도의 위치로 이동시킨다
- push가 아니기에 back 버튼이 존재하지 않는다 > 브라우저 상에서는 뒤로가기 버튼이 자동으로 있기에 가능
2-3 context.push
void push(String location, {Object? extra})
Type: void Function(String, {Object? extra})
package:go_router/src/misc/extensions.dart
Push a location onto the page stack.
- page stack에 location을 push > 이전 화면 위에 다른 화면을 올린다는 의미
- push를 사용하면 나중에 pop을 사용 할 수 있다
3) dart print
void main() {
print("다트 얏호");
}
- 함수를 실행하는 것 print 안에 string이라는 data type 을 전달하여 콘솔에 printing 해 주는 것
4) 숫자 ? Int , double, num
- int : 정수
- double : 소수점 숫자
- num : 모든 수
9월달도 화이팅
'TIL' 카테고리의 다른 글
20230904 TIL : 믿음의 월요일 라스고 (0) | 2023.09.04 |
---|---|
20230902 TIL : 중꺾마,, ! (5) | 2023.09.02 |
20230830 TIL : 급할수록 천천히 기초다지기 (0) | 2023.08.30 |
20230828 TIL : 월요일 좋아 싫어 (0) | 2023.08.28 |
20230826 TIL (1) | 2023.08.26 |