抛出了另一个异常:Assert失败:文件:/C:/src/flutter/packages/flutter/lib/src/widgets/navigator. dart:4532:12

0yycz8jy  于 12个月前  发布在  Flutter
关注(0)|答案(1)|浏览(168)
import 'package:flutter/material.dart';
import './interview.dart';
import './profilepage.dart';
import './googlesignup.dart';

class HomePage extends StatelessWidget {
  HomePage(
      {super.key, required this.mailId, required this.name, required this.pic});

  String mailId;
  String name;
  String pic = "";


  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Home page"),
        backgroundColor: Colors.amber,
        actions: [
          GestureDetector(
            onTap: () {
              Navigator.of(context).pop(
                MaterialPageRoute(
                    builder: (context) =>
                        ProfilePage("data:imJy+r2EKkN2l65xhRjrODuDOGSOX76eNM+9T5rwYd+OOOyAR0vA6w6+gjEQiUr+bqpnJ/uGmjaRdZFh40GKjdvH1pau8C0saW81R0lAty9idmf0CrPXpzp6gr11ZILJOuAAAAAAAAAAAAAA==",mailID: mailId, name: name, img: pic)),
                        

              );

              //ProfilePage(mailID: mailId, name: name, img: pic);
            }, 
            child: CircleAvatar(
              radius: 30,
              backgroundImage: NetworkImage(pic),
                 // "https://e7.pngegg.com/pngimages/442/477/png-clipart-computer-icons-user-profile-avatar-profile-heroes-profile.png"),
            ),
          )
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const DefaultTextStyle(
              style: TextStyle(
                  color: Colors.amber,
                  fontSize: 40,
                  fontWeight: FontWeight.bold),
              child: Text('Welcome to the interview'),
            ),
            //
            const SizedBox(height: 30,),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => Interviewimg(
                          isL2Locked: false,
                          isL3Locked: false,
                          isL4Locked: false,
                          2),
                    ),
                  );
                },
                child: const Text("Click to Take Interview")),
                const SizedBox(height: 20,),
                Container(
                  color: Colors.amber,
                  child: InkWell(onTap: (){},
                  child:TextButton(onPressed: () {
                    print("working");},
                    child: Text("TEST"),),),
                )

          ],
        ),
      ),
      
    );
  }
}

如果我试图从这个页面导航到下一个页面,它不允许我导航,错误是记录。我在这段代码中给了页面导航,这两个都不起作用。以前它是工作,而我在这个网页上工作,但当我连接的网页,它最终显示错误。我

toe95027

toe950271#

您提供的代码基本正确,但存在一些问题。在GestureDetectoronTap方法中,弹出当前页面,然后推送新页面。这可能不是你想要的行为。如果你想导航到一个新的页面,你应该只使用Navigator.pushNavigator.pop没有任何参数。

ElevatedButtononPressed方法推送一个新的Interviewimg页面。然而,Interviewimg构造函数是用一个数字(2)作为最后一个参数调用的,但不清楚这个数字应该表示什么。

我会给你正确的密码。

GestureDetector(
    onTap: () {
      Navigator.of(context).push(
        MaterialPageRoute(
          builder: (context) => ProfilePage(mailId: mailId, name: name, img: pic),
        ),
      );
    },
    child: CircleAvatar(
      radius: 30,
      backgroundImage: NetworkImage(pic),
    ),
  )

相关问题