Размер контейнера ограничен при использовании с BottomNavigationBar - PullRequest
0 голосов
/ 11 февраля 2020

У меня есть экран, который применяется с BottomNavigationBar. С индексом = 0 это приведет к home.dart.

Внутри home.dart я хочу иметь столбец виджетов. Он содержит 2 заголовка (помещены в виджеты Row) и 2 listViews. Первый ListView Я хочу, чтобы он прокручивался по горизонтали, а второй по вертикали. Оба ListView прокручивается. Однако кажется, что оба списка (или контейнера) каким-то образом ограничены по размеру, потому что 2-й режим прокрутки ListView заключается в том, что он прокручивается только внутри нижней половины экрана, а не на весь экран.

Я думал о добавление SingleChildScrollView с расширением за пределы всего контейнера в home.dart. Но он возвращает ошибку

mainScreen.dart

int _currentTab = 0;
void onTabTapped(int tabNumber) {
    setState(() {
      _currentTab = tabNumber;
    });
  }
@override
  void initState() {
    super.initState();
    this.setState(() {
      contents = [
        HomeTab(),
        DownloadedTab(),
        SettingTab()
      ];
    });
  }
@override
Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          title: Text('Home'),
        ),
        body: Container(
          child: contents != null ? contents[_currentTab] : Text("Page is loaded"),
        ),
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          onTap: onTabTapped,
          backgroundColor: Theme.ColorsMode.appBarGradientStart,
          currentIndex: _currentTab,
          items: [
            BottomNavigationBarItem(
              icon: new Icon(Icons.home),
              title: new Text('Home')),
            BottomNavigationBarItem(
              icon: new Icon(Icons.file_download),
              title: new Text('Download')),
            BottomNavigationBarItem(
              icon: new Icon(Icons.settings),
              title: new Text('Setting')),
          ],
        ),
      ),
    );
  }

home.dart

@override
Widget build(Build context) {
  return Container(
    child: Column(
      children: <Widget>[
          Row(
            children: <Widget>[
              Text('Course', textAlign: TextAlign.left, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
            ],
          ),
          Expanded(
            child: Container(
              // height: 6000.0,
              child: ListView.builder(
                physics: BouncingScrollPhysics(),
                scrollDirection: Axis.horizontal,
                itemCount: (showInHomeClass != null && showInHomeClass != null) ? showInHomeClass.length : 0,
                itemBuilder: (context, index) {
                  return Container(
                    width: MediaQuery.of(context).size.width * 0.6,
                    child: FittedBox(
                      fit: BoxFit.cover,
                      child: GestureDetector(
                        onTap: () {},
                        child: Card(
                          child: Center (
                            child: Image.network('https://example.com'),
                          ),
                        ),
                      ),
                    ),
                  );
                }
              ),
            ),
          ),
          Row(
            children: <Widget>[
              Text('News', textAlign: TextAlign.left, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
            ],
          ),
          Expanded(
            child: Container(
              // height: 6000.0,
              child: ListView.builder(
                physics: BouncingScrollPhysics(),
                scrollDirection: Axis.vertical,
                itemCount: (showInHomeClass != null && showInHomeClass != null) ? showInHomeClass.length : 0,
                itemBuilder: (context, index) {
                  return Container(
                    width: MediaQuery.of(context).size.width * 0.6,
                    child: FittedBox(
                      fit: BoxFit.cover,
                      child: GestureDetector(
                        onTap: () {},
                        child: Card(
                          child: Center (
                            child: Image.network('https://example.com'),
                          ),
                        ),
                      ),
                    ),
                  );
                }
              ),
            ),
          )
      ],
    ),
  );
}

Ошибка при добавлении SingleChildScrollView и Expanded


════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Listener:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 1786 pos 12: '_elements.contains(element)': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

The relevant error-causing widget was
    SingleChildScrollView 
lib\…\Home\Home.dart:115
#4      Element.inflateWidget 
package:flutter/…/widgets/framework.dart:3176
#5      Element.updateChild 
package:flutter/…/widgets/framework.dart:2988
#6      SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:5445
...
════════════════════════════════════════════════════════════════════════════════
Reloaded 6 of 675 libraries in 919ms.

════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 1786 pos 12: '_elements.contains(element)': is not true.
The relevant error-causing widget was
    SingleChildScrollView 

Есть предложения?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...