簡體   English   中英

顫振列表視圖

[英]Flutter listview

我正在做一項大學作業,我正在嘗試在“Cursos”課程中做一個列表視圖,這給我帶來了一些問題,如果有人能幫助我,我將不勝感激!

如果有人有解決方案,如何以及如何進行學校作業,如果它變得丑陋,就會出現問題。

錯誤:

════════ Exception caught by rendering library ═════════════════════════════════
'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 545 pos 12: 'child.hasSize': is not true.
The relevant error-causing widget was
ListView
lib\userscreen\userscreen.dart:82
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
Null check operator used on a null value
The relevant error-causing widget was
ListView
lib\userscreen\userscreen.dart:82
════════════════════════════════════════════════════════════════════════════════

主班

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:signupexample/Database/database_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:signupexample/main.dart';
import './avaliacao.dart';
import './consultoria.dart';
import './cursos.dart';
import './sair.dart';

class UserScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _UserScreen();
}

class _UserScreen extends State<UserScreen> with WidgetsBindingObserver {
  final dbHelper = DatabaseHelper.instance;
  Map<String, dynamic> _useData;
  bool _fetchingData = true;
  @override
  void initState() {
    _query();
    super.initState();
  }

  int indice = 0;
  static List<Widget> telas = <Widget>[
    Curso(),
    Consultoria(),
    Avaliacao(),
    Sair()
  ];
  void selecionar(int indice) {
    setState(
      () {
        this.indice = indice;
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        exit(0);
        return true;
      },
      child: Scaffold(
        appBar: AppBar(
          title: Text('Home'),
          automaticallyImplyLeading: true,
        ),
        bottomNavigationBar: BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              backgroundColor: Colors.red,
              icon: Icon(Icons.home),
              label: 'Cursos',
            ),
            BottomNavigationBarItem(
              backgroundColor: Colors.red,
              icon: Icon(Icons.business),
              label: 'Consultoria',
            ),
            BottomNavigationBarItem(
              backgroundColor: Colors.red,
              icon: Icon(Icons.warning_rounded),
              label: 'Avaliação',
            ),
            BottomNavigationBarItem(
              backgroundColor: Colors.red,
              icon: Icon(Icons.exit_to_app),
              label: 'Sair',
            ),
          ],
          currentIndex: this.indice,
          selectedItemColor: Colors.red[0],
          onTap: selecionar,
        ),
        body: _fetchingData
            ? CircularProgressIndicator()
            : ListView(
                children: [telas.elementAt(this.indice)],
              ),
      ),
    );
  }

  void _query() async {
    final allRows = await dbHelper.queryAllRows();
    print('query all rows:');

    allRows.forEach((row) => print(row));
    setState(() {
      _useData = allRows[0];
      _fetchingData = false;
    });
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setBool('isLogin', true);
  }
}

類 Cursos。 這是我想要制作列表視圖的課程

import 'package:flutter/material.dart';

class Curso extends StatefulWidget {
  State<StatefulWidget> createState() => _Curso();
}

class _Curso extends State<Curso> with WidgetsBindingObserver {
  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: const EdgeInsets.all(8),
      children: <Widget>[
        Container(
          height: 50,
          color: Colors.amber[600],
          child: const Center(child: Text('Entry A')),
        ),
        Container(
          height: 50,
          color: Colors.amber[500],
          child: const Center(child: Text('Entry B')),
        ),
        Container(
          height: 50,
          color: Colors.amber[100],
          child: const Center(child: Text('Entry C')),
        ),
      ],
    );
  }
}

添加shrinkWrap: true,到你的Curso 類ListView()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM