This is my code, it keeps showing up as "Dead Code." and it wont show anything in my AVD, can anyone help me with this?
import 'package:flutter/material.dart';
class SignInScreen extends StatelessWidget {
const SignInScreen({Key? key}) : super(key: key);
static String routeName = "/sign_in";
@override
Widget build(BuildContext context) {
return Scaffold();
AppBar();
}
}
CodePudding user response:
Firstly AppBar()
should be inside the Scaffold
widget.
The code should be something like this:
import 'package:flutter/material.dart';
class SignInScreen extends StatelessWidget {
const SignInScreen({Key? key}) : super(key: key);
static String routeName = "/sign_in";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar();
);
}
}
Secondly when you use return
the code below the return
statement doesn't execute, that is the reason your ide shows as a "dead code"
CodePudding user response:
You are returning the Scaffold widget without adding AppBar inside Scaffold widget so it will never work. try this:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Your Navigationbar title"),
),
body: Container(),
);
}
}