I keep getting this dark black screen

785 views
Skip to first unread message

Samuel Kingsley

unread,
Feb 26, 2019, 7:26:37 AM2/26/19
to Flutter Dev
Hi,
Am new with flutter, I've been doing xamarin forms, in fact am working on a project with xamarin forms, but I've been having issues with it. When I heard about flutter and gave it a try, mheeeennn! flutter is stew and the stew is sweet.
So far so good, I've been able to port 70% of my code to flutter, it's been working and I love it.

But, every page in my app shows black screen when navigated to, I want to believe this is just a minor issue, any help on why am getting this black screens that once worked would be highly appreciated.

Thanks.

Samuel Kingsley

unread,
Feb 27, 2019, 8:53:54 AM2/27/19
to Flutter Dev
Below is my code:

class HomeView extends StatefulWidget {
HomeView({Key key, this.title,this.user}) : super(key: key);
static String tag = 'home-page';
final User user;
final Object avatarTag=1;
final String title;

@override
Home createState() => Home();
}
class Home extends State<HomeView> {
// int _counter = 0;
static User _user;
final LatLng _center= const LatLng(45.521563,-122.677433);
RestDatasource datasource=new RestDatasource();
Future<User> user;

@override
void initState() {
super.initState();

user= datasource.getUser(context, RestDatasource.tokenResponse.accessToken, RestDatasource.tokenResponse.userName);
user.then((User user){
_user=user;
});
location.onLocationChanged().listen((location) async {
if(marker != null) {
mapController.removeMarker(marker);
}
marker = await mapController?.addMarker(MarkerOptions(
position: LatLng(location["latitude"], location["longitude"]),
));
mapController?.moveCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(
location["latitude"],
location["longitude"],
),
zoom: 20.0,
),
),
);
});
}
Future<Map<String, double>> _getLocation() async {
var currentLocation = <String, double>{};
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
}
return currentLocation;
}

var location=new Location();
Map<String, double> userLocation;

GoogleMapController mapController;
Marker marker;

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var textTheme = theme.textTheme;

Widget _buildLocationInfo(TextTheme textTheme) {
return new Row(
children: <Widget>[
new Icon(
Icons.place,
color: Colors.blueAccent,
size: 16.0,
),
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
"Hello world",
style: textTheme.subhead.copyWith(color: Colors.blueAccent),
),
),
],
);
}

Widget _createCircleBadge(IconData iconData, Color color,String type) {
return new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new FloatingActionButton(
child: new Icon(
iconData,
color: Colors.white,
size: 16.0,
),
onPressed: () {
if(type=="STREET_VIEW")
{

RestDatasource.prefsSave("MapType",type);
}
else if(type=="SATELLITE_VIEW")
{
RestDatasource.prefsSave("MapType",type);

}
else if(type=="TERRAIN_VIEW")
{
RestDatasource.prefsSave("MapType",type);

}
},
backgroundColor: Colors.deepPurple,
),

);
}

var linearGradient = const BoxDecoration(
gradient: const LinearGradient(
begin: FractionalOffset.centerRight,
end: FractionalOffset.bottomLeft,
colors: <Color>[Colors.white12, Colors.blueAccent]
// colors: <Color>[
// const Color(0xFF413070),
// const Color(0xFF2B264A),
// ],
),
);
return new Scaffold(
appBar:new AppBar(title: new Text("My App"),),
drawer: FlyoutMenu(),
body: new SingleChildScrollView(
child: new Container(
decoration: linearGradient,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new HomeHeader(
widget.user,
// avatarTag: widget.avatarTag,
),
new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(
"Samuel Kingsley",
style: textTheme.headline.copyWith(color: Colors.grey),
),
new Padding(
padding: const EdgeInsets.only(top: 4.0),
child: _buildLocationInfo(textTheme),
),
new Padding(
padding: const EdgeInsets.only(top: 16.0),
child: new Text(RestDatasource.tokenResponse.userName,
style:
textTheme.body1.copyWith(color: Colors.grey, fontSize: 16.0),
),
),
new Padding(
padding: const EdgeInsets.only(top: 16.0),
child: new Row(
children: <Widget>[
_createCircleBadge(Icons.streetview, Colors.white,"STREET_VIEW"),
_createCircleBadge(Icons.terrain, Colors.deepPurple,"TERRAIN_VIEW"),
_createCircleBadge(Icons.satellite, Colors.deepPurple,"SATELLITE_VIEW"),
],
),
),
new SizedBox.fromSize(
size: const Size.fromHeight(300.0),
child: Card(


child: GoogleMap(
onMapCreated: (GoogleMapController controller) {
mapController = controller;
mapController.addMarker(
MarkerOptions(
position:LatLng(
mapController.cameraPosition.target.latitude,
mapController.cameraPosition.target.longitude,),
infoWindowText: InfoWindowText("Random place","5 star rating"),
icon: BitmapDescriptor.defaultMarker

)
);

},
options: GoogleMapOptions(
cameraPosition: CameraPosition(
target: _center,

zoom: 11.0
),
myLocationEnabled: true,
trackCameraPosition: true,
compassEnabled: true,
zoomGesturesEnabled: true,

),)
),),

new HomeFooter(user:widget.user),

],
),
]),
),
)
);
}
}

...........

class HomeHeader extends StatelessWidget {
static const BACKGROUND_IMAGE = 'assets/images/mountains.jpg';

HomeHeader(this.user);

final User user;
// final Object avatarTag;

Widget _buildDiagonalImageBackground(BuildContext context) {
var screenWidth = MediaQuery.of(context).size.width;

return new DiagonallyCutColoredImage(
new Image.asset(
BACKGROUND_IMAGE,
width: screenWidth,
height: 280.0,
fit: BoxFit.cover,
),
color: Colors.blueAccent
// color: const Color(0xBB8338f4),
);
}

Widget _buildAvatar() {
// return new Hero(
// tag: avatarTag,

return new CircleAvatar(
// backgroundImage: new NetworkImage(user.imageUrl),
radius: 50.0,
);
// );
}

Widget _buildFollowerInfo(TextTheme textTheme) {
var followerStyle =
textTheme.subhead.copyWith(color: const Color(0xBBFFFFFF));

return new Padding(
padding: const EdgeInsets.only(top: 16.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text('90 Tracking', style: followerStyle),
new Text(
' | ',
style: followerStyle.copyWith(
fontSize: 24.0, fontWeight: FontWeight.normal),
),
new Text('100 Trackers', style: followerStyle),
],
),
);
}

Widget _buildActionButtons(ThemeData theme) {
return new Padding(
padding: const EdgeInsets.only(
top: 16.0,
left: 16.0,
right: 16.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_createPillButton(
'BUZZ ME',
backgroundColor:Colors.orangeAccent
),

new DecoratedBox(
decoration: new BoxDecoration(
border: new Border.all(color: Colors.white30),
borderRadius: new BorderRadius.circular(30.0),
),
child: _createPillButton(
'CALL ME',
textColor: Colors.white70,
),
),
],
),
);
}

Widget _createPillButton(
String text, {
Color backgroundColor = Colors.transparent,
Color textColor = Colors.white70,
}) {
return new ClipRRect(
borderRadius: new BorderRadius.circular(30.0),
child: new RaisedButton(
// minWidth: 140.0,
color: backgroundColor,
textColor: textColor,
onPressed: () {},
child: new Text(text),
),
);
}

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var textTheme = theme.textTheme;

return new Stack(
children: <Widget>[
_buildDiagonalImageBackground(context),
new Align(
alignment: FractionalOffset.bottomCenter,
heightFactor: 1.4,
child: new Column(
children: <Widget>[
_buildAvatar(),
_buildFollowerInfo(textTheme),
_buildActionButtons(theme),
],
),
),

],
);
}
}

Andrew Brogdon

unread,
Feb 27, 2019, 10:31:24 AM2/27/19
to Samuel Kingsley, Flutter Dev
That's a lot of code for someone interested in helping you to digest, and it doesn't include some important bits (I don't see a MaterialApp or runApp call anywhere, for example).

Have you tried temporarily paring down the code just to a simple home screen and one other page, just to see if you can replicate the issue? That would probably be a good first step, since it will assist the people here in diagnosing the problem.

-Andrew

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Kingsley

unread,
Feb 27, 2019, 7:24:14 PM2/27/19
to Flutter Dev
Thanks Andrew, I did what you suggested by "paring down the code" and I was able to see what the problem was. I was adding too many widgets in a widget control. I still don't know why this should be a problem. I thought that is allowed. Anyways, I've resolved it and thank you and everyone else who sent in a suggestion. I really appreciate.
Reply all
Reply to author
Forward
0 new messages