Emir Bolat
Emir Bolat

Reputation: 1049

Flutter - UnimplementedError

I started getting errors out of the blue with the following codes:

class app extends StatefulWidget {
  @override
  State<app> createState() => _appState();
}

String ad;
String profilFoto;

int selectedIndex;

class _appState extends State<app> {
  @override
  void initState()  {
    super.initState();
    //await FirebaseAuth.instance.signOut();
  PersistentTabController _controller = PersistentTabController(initialIndex: 0);
  Widget build(BuildContext context) {
    return PersistentTabView(
      context,
      controller: _controller,
        screens: _buildScreens(),
        items: _navBarsItems(),
        confineInSafeArea: true,
        backgroundColor: Colors.white, // Default is Colors.white.
        handleAndroidBackButtonPress: true, // Default is true.
        resizeToAvoidBottomInset: true, // This needs to be true if you want to move up the screen when keyboard appears. Default is true.
        stateManagement: true, // Default is true.
        hideNavigationBarWhenKeyboardShows: true, // Recommended to set 'resizeToAvoidBottomInset' as true while using this argument. Default is true.
        decoration: NavBarDecoration(
          borderRadius: BorderRadius.circular(10.0),
          colorBehindNavBar: Colors.white,
        ),
        popAllScreensOnTapOfSelectedTab: true,
        popActionScreens: PopActionScreensType.all,
        itemAnimationProperties: ItemAnimationProperties( // Navigation Bar's items animation properties.
          duration: Duration(milliseconds: 200),
          curve: Curves.ease,
        ),
        screenTransitionAnimation: ScreenTransitionAnimation( // Screen transition animation on change of selected tab.
          animateTabTransition: true,
          curve: Curves.ease,
          duration: Duration(milliseconds: 200),
        ),
        navBarStyle: NavBarStyle.style1, // Choose 
    );
  }
  void _onItemTapped(int index) {
    setState(() {
      selectedIndex  = index;
    });
  }
}
  List<Widget> _buildScreens() {
    return [
      MainScreen(),
      settingsScreen()
    ];
  }
    List<PersistentBottomNavBarItem> _navBarsItems() {
        return [
          PersistentBottomNavBarItem(
            icon: Icon(Icons.home),
            title: ("Görevler"),
            activeColorPrimary: Colors.blueAccent,
            inactiveColorPrimary: Colors.grey,
            textStyle: TextStyle(fontSize: 25),
          ),
          PersistentBottomNavBarItem(
            icon: Icon(Icons.person),
            title: ("Hesap"),
            activeColorPrimary: Colors.blueAccent,
            inactiveColorPrimary: Colors.grey,
            textStyle: TextStyle(fontSize: 25),
          ),
        ];
    }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    throw UnimplementedError();
  }
}

Error:

enter image description here

When I tried the code a few hours ago, it was not giving any errors. Now it started giving this error out of the blue. I didn't make any changes.

It started giving this error out of the blue. Thank you in advance for your valuable answers.

Upvotes: 0

Views: 2411

Answers (2)

DholaHardik
DholaHardik

Reputation: 502

class app extends StatefulWidget {
  @override
  State<app> createState() => _appState();
}

class _appState extends State<app> {
  String ad;
  String profilFoto;

  int selectedIndex;

  PersistentTabController _controller;

  @override
  void initState()  {
    super.initState();
    _controller = PersistentTabController(initialIndex: 0);
    //await FirebaseAuth.instance.signOut();
  }

  void _onItemTapped(int index) {
    setState(() {
      selectedIndex  = index;
    });
  }

  List<Widget> _buildScreens() {
    return [
      MainScreen(),
      settingsScreen()
    ];
  }

  List<PersistentBottomNavBarItem> _navBarsItems() {
    return [
      PersistentBottomNavBarItem(
        icon: Icon(Icons.home),
        title: ("Görevler"),
        activeColorPrimary: Colors.blueAccent,
        inactiveColorPrimary: Colors.grey,
        textStyle: TextStyle(fontSize: 25),
      ),
      PersistentBottomNavBarItem(
        icon: Icon(Icons.person),
        title: ("Hesap"),
        activeColorPrimary: Colors.blueAccent,
        inactiveColorPrimary: Colors.grey,
        textStyle: TextStyle(fontSize: 25),
      ),
    ];
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PersistentTabView(
        context,
        controller: _controller,
        screens: _buildScreens(),
        items: _navBarsItems(),
        confineInSafeArea: true,
        backgroundColor: Colors.white, // Default is Colors.white.
        handleAndroidBackButtonPress: true, // Default is true.
        resizeToAvoidBottomInset: true, // This needs to be true if you want to move up the screen when keyboard appears. Default is true.
        stateManagement: true, // Default is true.
        hideNavigationBarWhenKeyboardShows: true, // Recommended to set 'resizeToAvoidBottomInset' as true while using this argument. Default is true.
        decoration: NavBarDecoration(
          borderRadius: BorderRadius.circular(10.0),
          colorBehindNavBar: Colors.white,
        ),
        popAllScreensOnTapOfSelectedTab: true,
        popActionScreens: PopActionScreensType.all,
        itemAnimationProperties: ItemAnimationProperties( // Navigation Bar's items animation properties.
          duration: Duration(milliseconds: 200),
          curve: Curves.ease,
        ),
        screenTransitionAnimation: ScreenTransitionAnimation( // Screen transition animation on change of selected tab.
          animateTabTransition: true,
          curve: Curves.ease,
          duration: Duration(milliseconds: 200),
        ),
        navBarStyle: NavBarStyle.style1, // Choose
      ),
    );
  }
}

Upvotes: 1

redbnlrg
redbnlrg

Reputation: 277

It seems that you don't understand some Flutter's concepts. The widget tree shouldn't be in the initState() method but has to be part of the build() method, which is responsible to render Widget in your screen.

I advise you to read the following documentation :

As the TODO suggests, you have to implement the build function by returning a Widget as required in the return type.

  Widget build(BuildContext context) {
    return Scaffold(backgroundColor:Colors.teal); //your widgets here
  }

Upvotes: 0

Related Questions