The relevant error-causing widget was Scaffold when the exception was thrown, this was the stack

Zephys
  class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  final user = FirebaseAuth.instance.currentUser!;

  int index = 0;

  final pages = [
    Home(),
    Add(),
    Setting(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: pages[index],
      bottomNavigationBar: NavigationBarTheme(
        data: NavigationBarThemeData(
            indicatorColor: Colors.purpleAccent.withOpacity(0.5),
            labelTextStyle: MaterialStateProperty.all(const TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.bold,
            ))),
        child: NavigationBar(
          backgroundColor: Colors.white,
          animationDuration: const Duration(seconds: 1),
          labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
          height: 70,
          selectedIndex: index,
          onDestinationSelected: (index) {
            setState(() {
              this.index = index;
            });
          },
          destinations: const [
            NavigationDestination(
              selectedIcon: Icon(Icons.home),
              icon: Icon(Icons.home_outlined),
              label: '主頁',
            ),
            NavigationDestination(
              selectedIcon: Icon(Icons.add),
              icon: Icon(Icons.add_outlined),
              label: '加入',
            ),
            NavigationDestination(
              selectedIcon: Icon(Icons.settings),
              icon: Icon(Icons.settings_outlined),
              label: '設定',
            ),
          ],
        ),
      ),
    );
  }
}

The following StackOverflowError was thrown building _BodyBuilder: Stack Overflow

The relevant error-causing widget was Scaffold lib/Pages/home.dart:26 When the exception was thrown, this was the stack

As I am new in Flutter, can anyone tell me why am I getting this error?

Thanks.

Link to the error

Yeasin Sheikh

The main issue is you are calling Home inside the pages, similar like recursive thing,

  final pages = [
    Text(""), // use different widget instead of Home
    Add(),
    Setting(),
  ];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can an Exception be created/thrown with no stack trace?

Break when exception is thrown

Exception thrown when parsing data

Are stack traces generated when a Java exception is thrown?

Sending an email when an Exception is Thrown

A RenderFlex overflowed by 117 pixels on the bottom. The relevant error-causing widget was: Column

Error when trying to Scaffold a model

boost regex error_stack exception thrown from regex_search

Flutter - Positioned Widget in Stack causing Exception

Unhandled Exception Error when I have already thrown the errors in the method

No logs when exception is thrown in bot

A RenderFlex overflowed by 41 pixels on the bottom. The relevant error-causing widget was Column

Exception thrown in C with stack

"Another exception was thrown: Invalid argument(s)" error when building app

Exiting an app when an error is thrown without showing the stack trace on screen

Error handling when Exception / Error is thrown

Scaffold not found error in Flutter for BottomModalSheet widget even when it is defined inside a Scaffold

No Scaffold widget found when use BottomSheet

A RenderFlex overflowed by 4.8 pixels on the bottom. The relevant error-causing widget was Column

Facing "Each child must be laid out exactly once. The relevant error-causing widget was: Scaffold" error in flutter

RenderBox was not laid out : The relevant error-causing widget was ExpansionTile

No MediaQuery widget ancestor found.The relevant error-causing widget was FutureBuilder<FirebaseApp>

flutter error , The relevant error-causing widget was Scaffold

(Getting the error while building) setState() or markNeedsBuild() called during build.The relevant error-causing widget was MaterialApp

Exception thrown when it shouldn't be

Null check operator used on a null value The relevant error-causing widget was FutureBuilder<List<SearchModel>>

Null check operator used on a null value. The relevant error-causing widget was StreamBuilder<UserModel?>

The getter 'length' was called on null. The relevant error-causing widget was StreamBuilder<List<DocumentSnapshot<Object?>>>

The relevant error-causing widget was Column | flutter