我的项目的 firebase 存储桶中有图像,我想在 UI 中显示它们。我按照另一个堆栈溢出答案的说明进行操作,但它对我不起作用。
为了能够在 Flutter 网页上显示 Firebase 存储中的图像,您必须为 CORS 配置数据。
打开 GCP 控制台,选择您的项目,然后单击顶部导航栏中的 >_ 图标按钮启动云终端会话。单击打开编辑器按钮(铅笔图标),然后创建 cors.json 文件。运行 gsutil cors set cors.json gs://your-bucket cors.json 文件应如下所示:
[ { "origin": ["*"], "method": ["GET"], "maxAgeSeconds": 3600 } ] 我将 origin 设置为 * ,这意味着每个网站都可以显示您的图像。但您也可以在那里插入您网站的域名来限制访问。
如果您需要更多信息: https://cloud.google.com/storage/docs/configuring-cors
我在云平台上看到我的项目和存储桶的更新,但收到相同的错误消息:
Failed to load network image.
Image URL: gs://---------------------------------.png
Trying to load an image from another domain? Find answers at:
https://flutter.dev/docs/development/platform-integration/web-image
Run Code Online (Sandbox Code Playgroud)
我还遵循了这个人关于如何访问存储图像的教程。他使用了 Image.network 小部件,这也是我正在做的事情。它只是对我不起作用。下面的截图是我所看到的。黑框是存储位置的 URL。
如果主题在 main.dart 中设置为
return MaterialApp(
title: 'MY APP',
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'Cabin',
textTheme: TextTheme(
headline1: TextStyle(
fontFamily: 'Raleway',
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 18,
),
subtitle1: TextStyle(
fontFamily: 'Raleway',
color: Colors.black54,
fontWeight: FontWeight.w600,
fontSize: 16,
),
),
),
Run Code Online (Sandbox Code Playgroud)
我使用主题作为
Text('MY STRING',
style: Theme.of(context).textTheme.subtitle1),
Run Code Online (Sandbox Code Playgroud)
如何使“我的字符串”的颜色与 subtitle1 主题颜色不同,同时保留主题数据的其他属性,例如字体粗细、系列和大小等?