본문 바로가기

CS/Flutter | Dart

layout 이용해 코드 중복제거하기

layout 이용해 코드 중복제거하기

 

 

main_layout.dart

중복되는 코드를 main_layout.dart 파일로 따로 생성해준다

해당 코드 안에서 중복되지 않는 변수들은 아래처럼 정의해준다

class MainLayout extends StatelessWidget {
  final String title;
  final List<Widget> children;
  const MainLayout({required this.title, required this.children, Key? key})
      : super(key: key);

 

 

 

home_screen.dart
route1_screen.dart

 

Navigator를 이용해 Home Screen에서 Push 버튼을 누르면

RouteOne Screen으로 넘어가고

Pop 버튼을 누르면 다시 Home Screen으로 돌아온다

 

 

 

 


Tiny Star