Frontend/Flutter
[Flutter] remove AppBar leading icon, AppBar에서 뒤로가기 버튼 없애기
김룹
2024. 2. 12. 15:29
AppBar에서 leading 설정을 하지 않았는데도
뒤로가기 버튼이 표시되는 경우가 있다.
이럴경우,
AppBar의 속성 중에 automaticallyImplyLeading 속성을 false로 지정하면 됨! (기본값이 true 임)
👇 예시 코드
class SecondScreen extends StatelessWidget {
const SecondScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: const Text('Second Screen'),
),
body: Center(
child: ElevatedButton(
onPressed: () => Navigator.pop(context),
child: const Text('Go Back'),
),
),
);
}
}
⏬ automaticallyImplyLeading: false 적용을 하지 않는다면 기본 값이 true이기 때문에 아래와 같이 뒤로가기 버튼이 생성되어 있는 것을 볼 수 있다.
⏬ false로 지정해주면, 뒤로가기 버튼이 사라져 있는 것을 볼 수 있음!
🌐 공식 문서
https://api.flutter.dev/flutter/material/AppBar/automaticallyImplyLeading.html