Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当Flatter MaterialPartnerRoute导航到黑色背景的屏幕时,如何解决此问题?_Android_Ios_Flutter_Mobile - Fatal编程技术网

Android 当Flatter MaterialPartnerRoute导航到黑色背景的屏幕时,如何解决此问题?

Android 当Flatter MaterialPartnerRoute导航到黑色背景的屏幕时,如何解决此问题?,android,ios,flutter,mobile,Android,Ios,Flutter,Mobile,我第一次在我的一个项目中使用Flutter,这是一个报纸应用程序 当我尝试从main.dart导航到其他类别的newsfeed\u。dart使用MaterialPageRoute从我的Drawer导航时,会出现问题。在那个屏幕上显示的是新闻,但背景是黑色的。但是在屏幕newsfeed\u screen.dart中,它在我的main.dart的主体中被调用,它显示得非常完美 我在下面张贴代码 main.dart import 'package:flutter/material.dart'; imp

我第一次在我的一个项目中使用Flutter,这是一个报纸应用程序

当我尝试从
main.dart
导航到其他类别的
newsfeed\u。dart
使用
MaterialPageRoute
从我的
Drawer
导航时,会出现问题。在那个屏幕上显示的是新闻,但背景是黑色的。但是在屏幕
newsfeed\u screen.dart
中,它在我的
main.dart的主体中被调用,它显示得非常完美

我在下面张贴代码

main.dart

import 'package:flutter/material.dart';
import './SizeConfig.dart';
import './screens/newsfeed_screen.dart';
import 'package:curved_navigation_bar/curved_navigation_bar.dart';
import 'factory/widget_factory.dart';
import 'widgets/top_news_widget.dart';
import 'package:splashscreen/splashscreen.dart';
import './widgets/drawer.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Newspaper App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        //backgroundColor: Colors.lightGreenAccent,
      ),
      home: MyHomePage(title: 'The Business Standard'),
      routes: <String, WidgetBuilder> {
        '/screen1': (BuildContext context) => new NewsFeedScreen(216, 5, "Top News"),
        '/screen2' : (BuildContext context) => new NewsFeedScreen(4, 7, "National"),
        '/screen3' : (BuildContext context) => new NewsFeedScreen(13, 70, "International"),
        /*'/screen4' : (BuildContext context) => new Screen4()*/
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: '_MainScreenKey');

  Widget build(BuildContext context) {
    return SplashScreen(
        seconds: 3,
        navigateAfterSeconds: AfterSplash(),
        title: Text(
          'The Business Standard',
          style: TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 20.0
          ),
        ),
        image: Image.asset(
            'assets/TBS_logo.jpg',
        ),
        backgroundColor: Colors.white,
        styleTextUnderTheLoader: TextStyle(),
        photoSize: 100.0,
        onClick: ()=>print("Flutter Egypt"),
        loaderColor: Colors.red
    );
  }
}

class AfterSplash extends StatefulWidget {

  @override
  _AfterSplashState createState() => _AfterSplashState();
}

class _AfterSplashState extends State<AfterSplash> {
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: '_MainScreenKey');

  @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Image.asset(
              'assets/TBS.png',
              fit: BoxFit.cover,
              height: 45,
            )
          ],
        ),
        leading: IconButton(
          icon: Icon(Icons.dehaze),
          color: Colors.black,
          onPressed: () => _scaffoldKey.currentState.openDrawer(),
        ),
      ),
      drawer: SideDrawer(),
      body: NewsFeedScreen(22, 71, "Sports"),
      bottomNavigationBar: CurvedNavigationBar(
        backgroundColor: const Color(0xFF2b4849),
        items: <Widget>[
          Icon(Icons.bookmark, size: 30,),
          Icon(Icons.perm_identity, size: 30,),
          Icon(Icons.settings, size: 30,),
        ],
        onTap: (index) {
          if(index == 2) {
            _scaffoldKey.currentState.showSnackBar(const SnackBar(
                content: const Text('Will open Settings menu')));
          } else if(index == 0) {
            _scaffoldKey.currentState.showSnackBar(const SnackBar(
                content: const Text('Implement Bookmark function')));
          } else {
            _scaffoldKey.currentState.showSnackBar(const SnackBar(
                content: const Text('Will show User profile and information')));
          }
        },
      ),
    );
  }
}

import 'package:flutter/material.dart';
import '../SizeConfig.dart';
import '../screens/newsfeed_for_other_category.dart';

class SideDrawer extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return SizedBox(
      width: SizeConfig.safeBlockHorizontal*50,
      child: Theme(
        data: Theme.of(context).copyWith(canvasColor: const Color(0xFF2b4849)),
        child: Drawer(
          child: ListView(
            children: <Widget>[
              ListTile(
                title: Text(
                  'Top News',
                  style: TextStyle(
                      fontSize: 20,
                      color: Colors.white
                  ),
                ),
                onTap: () {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (BuildContext context) => NewsfeedForOtherCategory(216, 5, "Top News")
                      )
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“/SizeConfig.dart”;
导入“/screens/newsfeed_screen.dart”;
导入“包:弧形导航栏/弧形导航栏.省道”;
导入“factory/widget_factory.dart”;
导入“widgets/top_news_widget.dart”;
导入“包:splashscreen/splashscreen.dart”;
导入“./widgets/drawer.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“报纸应用程序”,
主题:主题数据(
主样本:颜色。蓝色,
//背景颜色:Colors.lightGreenAccent,
),
主页:我的主页(标题:“商业标准”),
路线:{
“/screen1”:(BuildContext上下文)=>NewsFeedScreen(216,5,“热门新闻”),
“/screen2”:(BuildContext上下文)=>NewsFeedScreen(4,7,“国家”),
“/screen3”:(BuildContext上下文)=>NewsFeedScreen(13,70,“国际”),
/*“/screen4”:(BuildContext上下文)=>new screen4()*/
},
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
int _计数器=0;
最终GlobalKey _scaffoldKey=新的GlobalKey(调试标签:“_MainScreenKey”);
小部件构建(构建上下文){
返回飞溅屏(
秒:3,
navigateAfterSeconds:AfterPlash(),
标题:正文(
“商业标准”,
样式:TextStyle(
fontWeight:fontWeight.bold,
字体大小:20.0
),
),
image:image.asset(
“资产/TBS_logo.jpg”,
),
背景颜色:Colors.white,
加载程序下的样式文本:TextStyle(),
photoSize:100.0,
onClick:()=>打印(“颤振埃及”),
装载颜色:颜色。红色
);
}
}
类afterplash扩展StatefulWidget{
@凌驾
_AfterPlashState createState();
}
类_afterplashState扩展状态

但是在我使用抽屉导航到的另一个类别的屏幕中,我看到的是如下黑色背景的
NewsfeedForOtherCategory

我尝试过使用
Navigator.of(context,rootNavigator:true).pushNamed('/route')
pushReplacementNamed()
来代替
MaterialPageRoute
。但是没有用

这是我发现的一个相关问题,我尝试了他们给出的解决方案,但对我无效

另外,我要导航到的页面没有
MaterialApp
小部件,只有
main.dart
有它。所以不应该有问题

我使用的是Ubuntu 16.04机器


你的一些线索将是无价的。非常感谢您的时间。

用脚手架将主容器包装在
NewsfeedForOtherCategory
中,您就有了解决方案

    ...
    return Scaffold(
      body: Container(
          alignment: Alignment.center,
          child: !_isRequestSent
              ? CircularProgressIndicator()
              : Container(
            child: ListView.builder(
                itemCount: newsPostList.length,
                scrollDirection: Axis.vertical,
                itemBuilder: (BuildContext context, int index) {
                  return _getNewsPostWidgets(index);
                }
            ),
          ),
        );
    );
    ...

在NewsfeedForOtherCategory小部件的构建功能中, 试着把你的东西包在脚手架上。 比如:


NewsfeedForOtherCategory
页面为黑色,因为它没有
材料
容器。 您可以简单地使用
材质
小部件或
脚手架
(它具有抽屉、浮动操作按钮等附加功能)包装它


从你的截图中我可以看到一些小部件被通知栏溢出了。您可以使用
SafeArea
内部
材料
支架
主体内部
来克服此问题

非常感谢你,伙计!向你致敬:-谢谢你对实际问题的解释。干杯
    ...
    return Scaffold(
      body: Container(
          alignment: Alignment.center,
          child: !_isRequestSent
              ? CircularProgressIndicator()
              : Container(
            child: ListView.builder(
                itemCount: newsPostList.length,
                scrollDirection: Axis.vertical,
                itemBuilder: (BuildContext context, int index) {
                  return _getNewsPostWidgets(index);
                }
            ),
          ),
        );
    );
    ...
    return Scaffold(
              body: Container(
                alignment: Alignment.center,
                child: !_isRequestSent
                    ? CircularProgressIndicator()
                    : Container(
                        child: ListView.builder(
                            itemCount: newsPostList.length,
                            scrollDirection: Axis.vertical,
                            itemBuilder: (BuildContext context, int index) {
                              return _getNewsPostWidgets(index);
                            }),
                      ),
              ),
            ),