ScreenArguments Topic
화면 파라메터 ScreenArguments (lib/screen_arguments)
화면에 전달할 파라메터들을 정의하는 파일들입니다.
Named Route에서는 화면전환시 객체를 직접 생성하는게 아니라 string으로 전달하기 때문에 Arguments 객체를 만들어 내비게이터에 전달하는 방법을 사용합니다.
사용 예시
Navigator.of(context, rootNavigator: true).pushNamed(ReportScreen.routeName, arguments: ReportScreenArguments(reportGroup: ReportGroup.cowHistory, cow: cow));
파라메터 전달이 필요한 새로운 화면을 구현하는 방법
- 화면 파일을 생성합니다.
class ReportScreen extends StatefulWidget implements ScreenImpl {
final ReportGroup reportGroup;
final Cow? cow;
ReportScreen({
Key? key,
required this.reportGroup,
this.cow,
}) : super(key: key);
@override
State<StatefulWidget> createState() => ReportScreenState();
@override
String get title => reportGroup.name;
static const routeName = "/report";
}
- ScreenArguments 클래스를 생성합니다.
class ReportScreenArguments {
final ReportGroup reportGroup;
final Cow? cow;
ReportScreenArguments({
required this.reportGroup,
this.cow,
});
}
AppEntry
에 있는MaterialApp
위젯의onGenerateRoute
에 다음과 같이 정의해줍니다.
...
/// ReportScreen 화면일 때
case ReportScreen.routeName:
/// 전달된 arguments를 RerportScreenArguments 객체로 변환합니다.
final args = settings.arguments as ReportScreenArguments;
/// ReportScreen을 생성하면서 arguments를 전달해줍니다.
return MaterialPageRoute(builder: (context) => ReportScreen(reportGroup: args.reportGroup, cow: args.cow), settings: settings);
...
Classes
- ChatListSubscreenArguments ScreenArguments
- CowDetailScreenArguments ScreenArguments
- DateTimePickerScreenArguments ScreenArguments
- DiseaseObservationCreateScreenArguments ScreenArguments
- PhoneAuthScreenArguments ScreenArguments
- PhotoViewScreenArguments ScreenArguments
- PopupScreenArguments ScreenArguments
- 팝업 화면에 전달하는 파라메터입니다.
- ReportScreenArguments ScreenArguments
- WebviewScreenArguments ScreenArguments