Flutter无法在文本中使用Google字体

发布于 2025-02-13 03:10:45 字数 1658 浏览 0 评论 0原文

当我尝试使用Google_fonts时,我会收到这样的错误。我还导入了库,并将“ google_fonts: ^3.0.1”添加到“ pub.yml”文件中。 。

“我添加了 =“控制台错误映像”>

void main() {
  runApp(BenimUyg());
}

class BenimUyg extends StatelessWidget {
  const BenimUyg({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.brown[300],
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: const <Widget>[
                CircleAvatar(
                  backgroundColor: Colors.lime,
                  backgroundImage: AssetImage("assets/images/kahve.jpg"),
                  radius: 70,
                ),
                Text(
                  "Flutter Kahvecisi",
                  style: TextStyle(
                    fontSize: 40,
                    fontFamily: "Courgette",
                    color: Colors.brown,
                  ),
                ),
                // ignore: unnecessary_const
                Text(
                  "Çok Yakındasınız",
                  style: GoogleFonts.pacifico(
                    textStyle: TextStyle(
                      color: Colors.lime,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

When I try to use google_fonts I get an error like this. I also imported the library and added " google_fonts: ^3.0.1" to the "pub.yml" file.
" I added.

Console error image

Code line error image

void main() {
  runApp(BenimUyg());
}

class BenimUyg extends StatelessWidget {
  const BenimUyg({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.brown[300],
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: const <Widget>[
                CircleAvatar(
                  backgroundColor: Colors.lime,
                  backgroundImage: AssetImage("assets/images/kahve.jpg"),
                  radius: 70,
                ),
                Text(
                  "Flutter Kahvecisi",
                  style: TextStyle(
                    fontSize: 40,
                    fontFamily: "Courgette",
                    color: Colors.brown,
                  ),
                ),
                // ignore: unnecessary_const
                Text(
                  "Çok Yakındasınız",
                  style: GoogleFonts.pacifico(
                    textStyle: TextStyle(
                      color: Colors.lime,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念三年u 2025-02-20 03:10:45

该问题来自儿童:const&lt; widget&gt; [删除const

 child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[ // here
                CircleAvatar(
                  backgroundColor: Colors.lime,
                  backgroundImage: AssetImage("assets/images/kahve.jpg"),
                  radius: 70,
                ),
class BenimUyg extends StatelessWidget {
  const BenimUyg({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.brown[300],
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                const CircleAvatar(
                  backgroundColor: Colors.lime,
                  backgroundImage: AssetImage("assets/images/kahve.jpg"),
                  radius: 70,
                ),
                const Text(
                  "Flutter Kahvecisi",
                  style: TextStyle(
                    fontSize: 40,
                    fontFamily: "Courgette",
                    color: Colors.brown,
                  ),
                ),
                // ignore: unnecessary_const
                Text(
                  "Çok Yakındasınız",
                  style: GoogleFonts.pacifico(
                    textStyle: const TextStyle(
                      color: Colors.lime,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

The issue is coming from children: const <Widget>[ remove const.

 child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[ // here
                CircleAvatar(
                  backgroundColor: Colors.lime,
                  backgroundImage: AssetImage("assets/images/kahve.jpg"),
                  radius: 70,
                ),
class BenimUyg extends StatelessWidget {
  const BenimUyg({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.brown[300],
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                const CircleAvatar(
                  backgroundColor: Colors.lime,
                  backgroundImage: AssetImage("assets/images/kahve.jpg"),
                  radius: 70,
                ),
                const Text(
                  "Flutter Kahvecisi",
                  style: TextStyle(
                    fontSize: 40,
                    fontFamily: "Courgette",
                    color: Colors.brown,
                  ),
                ),
                // ignore: unnecessary_const
                Text(
                  "Çok Yakındasınız",
                  style: GoogleFonts.pacifico(
                    textStyle: const TextStyle(
                      color: Colors.lime,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文