I have set up my main.dart as a welcome screen with a login button and a search button, but I don't want the navigation bar to appear there. I created a second file ("featured.dart") where I would like the navigation bar to begin, and for the rest of the pages on the app it will always be there (so, after you click away from the welcome screen, you will never see it again. Check out the Spotify welcome screen for a good example). However, when I try to put my NavigationBar object inside a Scaffold starting on featured.dart aka not my starting page, the app crashes. No error report or debug notice, and the code looks clean. What am I missing?
Here's the code for 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,
),
],
),
),
],
);
}
}
And here's the code for featured.dart, where I want the toolbar to start ("TEXT ONE" redirects to this):
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;
});
},
),
),
],
);
}
}
Thanks!
UPDATE: Update. I got rid of the "MaterialApp" instance in featured.dart as suggested by @RémiRousselet and replaced it with a Scaffold. Now it still crashes but I have a backtrace:
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.
Final edit: I solved the problem. The issue was that I was establishing the main.dart as the current page but making it impossible to define i as that page, so there was no way or page[index] to reconcile. Thanks for the help!
I solved the problem. The issue was that I was establishing the main.dart as the current page but making it impossible to define i as that page, so there was no way or page[index] to reconcile. Thanks for the help!
User contributions licensed under CC BY-SA 3.0