gpt4 book ai didi

android - “SystemChrome”未在 Flutter 中定义

转载 作者:IT王子 更新时间:2023-10-29 07:11:40 27 4
gpt4 key购买 nike

我是 Flutter 的新手,我想更改应用的状态栏颜色。经过一番谷歌搜索后,我找到了一种方法。就是在我的main函数中添加如下代码。

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white
));

但是在添加它并运行我的应用程序后,我收到了以下错误:-

Compiler message:                                                       
lib/main.dart:15:40: Error: Method not found: 'SystemUiOverlayStyle'.
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
^^^^^^^^^^^^^^^^^^^^
lib/main.dart:15:3: Error: Getter not found: 'SystemChrome'.
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
^^^^^^^^^^^^

请告诉我问题是什么。提前致谢!


我的主要函数:-

void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white
));
runApp(WilliamClient());
}

我的 pubspec.yaml 文件:-

name: william_client
description: Client App for William Assistant and TV.
version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
firebase_auth: 0.8.4+5
cloud_firestore: 0.10.1
flutter:
sdk: flutter
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
sdk: flutter

flutter:

fonts:
- family: Montserrat
fonts:
- asset: fonts/Montserrat.ttf
- family: MontserratLight
fonts:
- asset: fonts/Montserrat-Light.ttf
- family: RobotoMono
fonts:
- asset: fonts/RobotoMono.ttf

最佳答案

你应该添加

import 'package:flutter/services.dart';

关于android - “SystemChrome”未在 Flutter 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56022639/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com