• 카테고리

    질문 & 답변
  • 세부 분야

    모바일 앱 개발

  • 해결 여부

    미해결

질문있습니다.

24.01.02 19:16 작성 24.01.02 19:16 수정 조회수 133

0

basket screen에서 appBar에 뒤로가기 기능을 입혀보려고 합니다. 다른 페이지들은 가능한데, 장바구니 페이지에서는 뒤로가기 기능이 안되더라고요, paginationListview로 씌우고 <BasketITemModel>를 넣으려고 해서 안되는 것 같은데요, 이게 가능하도록 하려면 어떻게 해야할까요?

답변 1

답변을 작성해보세요.

0

안녕하세요!

"안된다"라는 말씀만 해주시면 도움을 드리기 어렵습니다.

어떤게 어떻게 안되는지 설명을 해주셔야 제가 판단을 하고 답변을 드릴 수 있습니다.

"뒤로가기 기능이 안된다"라는게 무슨 말씀이신지 정확히 예시를 들어주시면 답변 드리겠습니다. (현재 플러터 프레임워크의 뒤로가기 기능에 버그는 없는걸로 확인됩니다)

감사합니다!

김지현님의 프로필

김지현

질문자

2024.01.04

제가 설정한 코드는 다음과 같습니다.(DefaultLayout)

import 'package:flutter/material.dart';

class DefaultLayout extends StatelessWidget {

final Widget child;
final Color? 
backgroundColor;
final String? title;
final Widget? leading;
final Widget? bottomNavigationBar;
final VoidCallback? onPressed;
final Widget? floatingActionButton;
final bool isMainPage;

const DefaultLayout({
required this.child,
this.backgroundColor,
this.title,
this.leading,
this.bottomNavigationBar,
this.onPressed,
this.floatingActionButton,
this.isMainPage = false,
super.key,
});

@override Widget build(BuildContext context) {

return Scaffold(
backgroundColor: backgroundColor ?? Colors.white,
appBar: renderAppBar(
context: context,
onPressed: onPressed,
isMainPage: isMainPage,
),
floatingActionButton: floatingActionButton,
body: child,
bottomNavigationBar: bottomNavigationBar,
);
}

AppBar? renderAppBar({
required BuildContext context,
required VoidCallback? onPressed,
required bool isMainPage,
}) {
if (title == null) {
return null;
}
return AppBar(
backgroundColor: Colors.white,
centerTitle: true,
title: Text(title!,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
leading: isMainPage
? null 
: IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.black,
),
onPressed: onPressed,
),
);
}
}

그런 다음에 매 페이지에,
return DefaultLayout(
title: '장바구니',
isMainPage: false,
onPressed: () {
Navigator.of(context).pop();
},

 

이런식으로 코딩을 해봤는데요, 결과는, 직전 페이지가 뜨지 않았습니다.

이렇게 검은색 창이 뜨고

You have popped the last page off of the stack, there are no pages left to show

'package:go_router/src/delegate.dart':

Failed assertion: line 116 pos 7: 'currentConfiguration.isNotEmpty'

 

라는 오류를 보내줍니다. 직전 뒤로가기 가능을 넣으려면 어떤 코드를 넣어야 할까요?

에러 메세지는 you have popped last page off of the stack 입니다.

라우터 스택에서 마지막 페이지인데 뒤로 가기를 했다고 번역 할 수 있는데요.

쉽게 말해서 마지막 페이지라 뒷 페이지가 없으니 현재 페이지를 없애면 아무 페이지도 존재하지 않는 검정 페이지가 뜨는 현상입니다.

아마 라우팅을 잘못하신 것 같은걸로 생각되는데 확인 해보시면 쉽게 해결 가능 할 듯 합니다!