Search code examples
flutterdartappbar

AppBar not working and considered as dead code


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();
  }
}

Solution

  • 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"