我已将main.dart设置为带有登录按钮和搜索按钮的欢迎屏幕,但我不希望导航栏出现在那里 . 我创建了第二个文件(“featured.dart”),我希望导航栏开始,对于应用程序中的其余页面,它将始终存在(因此,在您单击远离欢迎屏幕后,您永远不会再看到它 . 查看Spotify欢迎屏幕以获得一个很好的例子) . 但是,当我尝试将我的NavigationBar对象放在一个脚手架中,从特色项目开始,而不是我的起始页面,应用程序崩溃了 . 没有错误报告或调试通知,代码看起来很干净 . 我错过了什么?
这是main.dart的代码:
import 'package:flutter/material.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
import 'featured.dart';
import 'profile.dart';
import 'package:flutter/cupertino.dart';
void main() => runApp(RambleApp());
class RambleApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Title",
home: VideoBG(),
);
}
}
class VideoBG extends StatefulWidget {
@override
VideoState createState() => VideoState();
}
class VideoState extends State<VideoBG> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = new VideoPlayerController.asset('assets/Video.mp4');
}
@override
Widget build(BuildContext context) {
return new Stack(
fit: StackFit.passthrough,
children: [
new ClipRect(
child: new OverflowBox(
maxWidth: double.infinity,
maxHeight: double.infinity,
alignment: Alignment.center,
child: new FittedBox(
fit: BoxFit.cover,
alignment: Alignment.center,
child: new Container(
child: new Chewie( //video player
_controller,
autoPlay: true,
looping: true,
autoInitialize: true,
showControls: false,
),
),
),
),
),
new Container(
margin: EdgeInsets.all(40.0),
decoration: BoxDecoration(
image: DecorationImage(
alignment: Alignment(0.0, -0.75),
image: AssetImage('assets/title.png')
),
),
),
new Container(
alignment: new Alignment(0.0, 0.65),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Container(
child: new FlatButton(
child: new Text(
'TEXT ONE',
style: new TextStyle(
fontWeight: FontWeight.w900,
fontSize: 17.5,
),
),
color: Color(0xFF70E0EF),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(7.5)
),
onPressed: () {
_controller.pause();
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => new FeaturedScreen()),
);
},
),
width: 150.0,
height: 60.0,
),
new Container(
child: new OutlineButton(
child: new Text(
'TEXT TWO',
style: new TextStyle(
fontWeight: FontWeight.w900,
fontSize: 17.5,
),
),
borderSide: new BorderSide(
color: const Color(0xFF70E0EF),
width: 5.0,
style: BorderStyle.solid,
),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(7.5),
),
onPressed: () {
_controller.pause();
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => new ProfileScreen()),
);
},
),
width: 150.0,
height: 60.0,
),
],
),
),
],
);
}
}
这里是featured.dart的代码,我希望工具栏开始(“TEXT ONE”重定向到此):
import 'package:flutter/material.dart';
import 'profile.dart';
import 'search.dart';
import 'favorites.dart';
class FeaturedScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Featured(),
theme: new ThemeData(canvasColor: Color(0xffffffff).withOpacity(0.5)),
);
}
}
class Featured extends StatefulWidget {
@override
FeaturedState createState() => FeaturedState();
}
class FeaturedState extends State<Featured>{
int i = 0;
var pages = [
new FeaturedScreen(),
new ProfileScreen(),
new SearchScreen(),
new FavoritesScreen(),
];
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.passthrough,
children: [
new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('assets/FeaturedBG.png'),
fit: BoxFit.cover
),
),
),
new Scaffold(
body: pages[i],
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: i==0?Icon(
Icons.apps,
color: Color(0xff70E0EF),
size: 35.0,
):Icon(
Icons.apps,
color: Colors.black,
size: 35.0,
),
title: Text(
'Collections',
style: new TextStyle(
color: Colors.white,
fontSize: 0.0,
height: 0.0,
),
),
),
BottomNavigationBarItem(
icon: i==1?Icon(
Icons.search,
color: Color(0xff70E0EF),
size: 35.0,
):Icon(
Icons.search,
color: Colors.black,
size: 35.0,
),
title: Text(
'Search',
style: new TextStyle(
color: Colors.white,
fontSize: 0.0,
height: 0.0,
),
),
),
BottomNavigationBarItem(
icon: i==2?Icon(
Icons.favorite,
color: Color(0xff70E0EF),
size: 35.0,
):Icon(
Icons.favorite,
color: Colors.black,
size: 35.0,
),
title: Text(
'Favorites',
style: new TextStyle(
color: Colors.white,
fontSize: 0.0,
height: 0.0,
),
),
),
BottomNavigationBarItem(
icon: i==3?Icon(
Icons.person,
color: Color(0xff70E0EF),
size: 35.0,
):Icon(
Icons.person,
color: Colors.black,
size: 35.0,
),
title: Text(
'Profile',
style: new TextStyle(
color: Colors.white,
fontSize: 0.0,
height: 0.0,
),
),
),
],
type: BottomNavigationBarType.fixed,
currentIndex: i,
onTap: (int index) {
setState((){
i = index;
});
},
),
),
],
);
}
}
谢谢!
更新:更新 . 我按照@RémiRousselet的建议删除了feature.dart中的“MaterialApp”实例,并将其替换为Scaffold . 现在它仍然崩溃,但我有一个回溯:
W/MapperHal( 5503): buffer descriptor with invalid usage bits 0x2000
D/ ( 5503): HostConnection::get() New Host Connection established 0xebd088c0, tid 5633
F/libc ( 5503): Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xd9002fec in tid 5592 (1.ui), pid 5503 (ample.rambleapp)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/sdk_gphone_x86/generic_x86:9/PPP3.180510.007/4799589:user/release-keys'
Revision: '0'
ABI: 'x86'
pid: 5503, tid: 5592, name: 1.ui >>> com.example.rambleapp <<<
signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xd9002fec
eax d7125400 ebx da2b4aac ecx d7125400 edx d90ff970
edi d9003090 esi d90030c0
ebp d9003018 esp d9002ff0 eip d9a073ac
backtrace:
#00 pc 009073ac /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#01 pc 0090a071 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#02 pc 0092ea7b /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#03 pc 00931eda /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#04 pc 00933533 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#05 pc 00933cd6 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#06 pc 006a8728 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#07 pc 0080a35c /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#08 pc 00698076 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#09 pc 0060371f /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#10 pc 0093089b /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#11 pc 00694bb4 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#12 pc 006a09e2 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#13 pc 006a0ba5 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#14 pc 0090986b /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#15 pc 008f69b2 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#16 pc 008e9b27 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#17 pc 008ffb73 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#18 pc 008ec080 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#19 pc 008f403e /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#20 pc 008e9af3 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#21 pc 008ebd38 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#22 pc 008f992f /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#23 pc 008ebd68 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#24 pc 008ef806 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#25 pc 008f0967 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#26 pc 009131ce /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#27 pc 0092ea84 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#28 pc 00931eda /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#29 pc 00933533 /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#30 pc 00932cdb /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#31 pc 0092effa /data/app/com.example.rambleapp-YanUsKDV8Z_MFyb-cLaaAw==/lib/x86/libflutter.so
#32 pc 0000056b <anonymous:d7840000>
Lost connection to device.
最后编辑:我解决了这个问题 . 问题是我正在 Build main.dart作为当前页面,但是无法将i定义为该页面,因此没有办法或页面[index]进行协调 . 谢谢您的帮助!
1 回答
我解决了这个问题 . 问题是我正在 Build main.dart作为当前页面,但是无法将i定义为该页面,因此没有办法或页面[index]进行协调 . 谢谢您的帮助!