【问题标题】:flutter error , The relevant error-causing widget was Scaffoldflutter error ,相关的导致错误的小部件是 Scaffold
【发布时间】:2021-12-29 11:20:22
【问题描述】:

我的代码运行良好,在我尝试将我的代码链接到 Firestore 后,突然出现了这个错误,我仍然无法解决。

════════ Exception caught by rendering library ═════════════════════════════════

Each child must be laid out exactly once.
The relevant error-causing widget was
Scaffold    
lib\pages\nav.dart:26
import 'package:MeeM/pages/notification.dart';
import 'package:MeeM/pages/user.dart';
import 'package:flutter/material.dart';
import 'package:MeeM/pages/Home.dart';
import 'package:MeeM/pages/search.dart';
import 'package:MeeM/add/add.dart';
import 'package:MeeM/profileUI/profile.dart';
import 'package:MeeM/pages/signup_page.dart';

// ignore: camel_case_types
class nav extends StatefulWidget {
  @override
  _navState createState() => _navState();
}

// ignore: camel_case_types
class _navState extends State<nav> {
  int _currentindex = 0;
  List<Widget> _widgeroption = <Widget>[
    Home(currentUser: currentUser),
    search(),
    add(currentUser: currentUser),
    notification(),
    profile(profileId: currentUser?.id),
  ];

  void _onItemTap(int index) {
    setState(() {
      _currentindex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentindex,
        children: _widgeroption,
      ),
      bottomNavigationBar: BottomNavigationBar(
        elevation: 0,
        type: BottomNavigationBarType.fixed,
        backgroundColor: Colors.white,
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            // ignore: deprecated_member_use
            icon: Icon(
              Icons.home_outlined,
              color: Colors.black,
              size: 30,
            ),
            label: 'home',
          ),
          BottomNavigationBarItem(
            // ignore: deprecated_member_use
            icon: Icon(
              Icons.search,
              color: Colors.black,
              size: 30,
            ),
            label: 'search',
          ),
          BottomNavigationBarItem(
            // ignore: deprecated_member_use
            icon: Icon(
              Icons.add_box_outlined,
              color: Colors.black,
              size: 30,
            ),
            label: 'upload',
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.notifications_none_outlined,
              color: Colors.black,
              size: 30,
            ),
            label: 'feed',
          ),
          BottomNavigationBarItem(
            // ignore: deprecated_member_use
            icon: Icon(
              Icons.person,
              color: Colors.black,
              size: 30,
            ),
            label: 'profile',
          ),
        ],
        showSelectedLabels: false,
        showUnselectedLabels: false,
        currentIndex: _currentindex,
        onTap: _onItemTap,
      ),
    );
  }
}
~~~!

【问题讨论】:

    标签: android flutter dart mobile


    【解决方案1】:

    你只需要运行flutter clean,然后运行flutter pub get命令并重新运行你的项目。

    【讨论】:

    • 它不起作用
    • 尝试擦除你的模拟器的数据然后同样的过程
    • 如果我换了模拟器就可以解决
    • 是的,但不要忘记运行 pub clean 和 pub get
    猜你喜欢
    • 2021-01-30
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2021-11-13
    • 2021-12-22
    • 2021-03-03
    相关资源
    最近更新 更多