Flutter中状态栏不显示

17

Flutter应用程序未显示状态栏(请参见下图)。我不想要全屏视图。 有没有解决这个问题的方法。

图像

main.dart

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
 return MaterialApp(
  title: '',
  theme: ThemeData(
    primarySwatch: Colors.purple,
    fontFamily: 'FIRSNEUE'
  ),
 
 home: SplashScreenFirst(),

  routes: <String, WidgetBuilder> {
    '/dashboard': (BuildContext context) => Dashboard(title: ''),
    '/login': (BuildContext context) =>  Login(),
    '/service-dashboard': (BuildContext context) => Service(),
    '/service-exists': (BuildContext context) => ServiceExists(),
    '/partnerOffers' : (BuildContext context) => Partner(),
    '/visitorRequest' : (BuildContext context) => VisitorRequest(),
    '/vistorRequestSuccess' : (BuildContext context) => VisitorRequestSuccess(),
    '/mealPlan' : (BuildContext context) => MealPlan()
  },
  
);
}
}

登录.dart

return Scaffold(
    key: _scaffoldKey,
    body: ListView(
        shrinkWrap: true,
        padding: EdgeInsets.all(15.0),
        children: <Widget>[
          Center(
            child: Container(
              child: Column(
                children: <Widget>[
                  Container(
                      padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                      width: double.infinity,
                      height: 720,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          SizedBox(height: 65.0),
                          SizedBox(
                            height: 43.0,
                            width: 136,
                            child: Image.asset(
                              "images/logo.png",
                              fit: BoxFit.cover,
                            ),
                          ),
                          SizedBox(height: 45.0),
                          Text(
                            'Please login to continue',
                            style: TextStyle(
                                color: Color(0xffB13F8F),
                                fontSize: 16,
                                letterSpacing: 0.15),
                          ),
                          SizedBox(height: 145.0),
                          emailField,
                          _error
                              ? _phoneController.text.length > 0
                                  ? (SizedBox(
                                      height: 1,
                                    ))
                                  : Container(
                                      padding: EdgeInsets.only(top: 20),
                                      child: Text(
                                        'Something went wrong. Please try again',
                                        style: TextStyle(
                                            color: Colors.redAccent,
                                            fontSize: 16),
                                      ),
                                    )
                              : (SizedBox(
                                  height: 1,
                                )),
                          SizedBox(
                            height: 104.0,
                          ),
                          _isLoading
                              ? Center(child: CircularProgressIndicator())
                              : _isDisabled
                                  ? loginButtonDisabled
                                  : loginButon,
                          SizedBox(
                            height: 15.0,
                          ),
                        ],
                      ))
                ],
              ),
            ),
          ),
        ]));
 }

3
请提供您的代码。 - Viren V Varasadiya
6个回答

38

请检查创建Flutter项目时生成的两个文件,并注释或删除以下内容:

  • ./ios/Runner/Info.plist
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIStatusBarHidden</key>                <- <here>
<true/>                                     <- <here>
<key>UISupportedInterfaceOrientations</key>
  • ./android/app/src/main/res/values/styles.xml
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
    <item name="android:windowFullscreen">true</item>  <- <here>

3
对于IOS: 请检查创建Flutter项目时创建的两个文件,并将值从false更新为true。
./ios/Runner/Info.plist
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/> -> Change to true

就是这样了。非常感谢你! - undefined

1

只需使用 SafeArea 组件包装您的脚手架,您的顶部边缘就不会触及状态栏。


0

只需在Android中添加两行代码 -> app -> src -> main -> res -> values -> styles.xml

<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

0
一个仅限于Flutter的解决方案是将您的Scaffold包裹在以下代码中:
    AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark,
      child: Scaffold(
        ...
      )

这将把您的状态栏项目设置为黑色。如果您希望您的应用程序依赖于设备的主题,您应该在设置AnnotatedRegion上的暗色或亮色设置时考虑Theme.of(context).brightness。

-5

我不确定您所说的状态栏是否指应用程序栏。如果您的主要小部件不是Scaffold,那么可能没有该栏。请将所有代码放在以下语句中:

Scaffold(
    appBar: AppBar(
      title: const Text('Sample Code'),
    ),
    body: //rest of code...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接