StatelessWidget에서 잘 쓰던 pushNamed가 StatefulWidget에서 작동하지 않는다면
BuildContext가 다르기 때문이다.
보통 예제에서 StatelessWidget 안에 StatefulWidget을 불러와 쓰기에 StatefulWiget을 호출할 때 context를 넘겨주면 Navigator.pushNamed가 정상 작동했다.
class Products extends StatefulWidget {
final BuildContext ctx;
const Products(this.ctx, {super.key});
@override
State<StatefulWidget> createState() {
return _Products(ctx);
}
}
class _Products extends State<Products> {
final BuildContext ctx;
_Products(this.ctx);
...
Navigator.pushNaemd(ctx, "/d");
}
'프로그래밍' 카테고리의 다른 글
동시성, 병렬성, 동기, 비동기 (0) | 2025.09.10 |
---|---|
누적합으로 부분합 구하기 (5) | 2025.08.06 |