CustomScrollView within ExpansionTile错误

问题描述 投票:0回答:1

试图通过阅读一些文档和一些公开的问题来解决这个问题,但并不幸运。谁能帮助我?

我得到这个错误。

类型'bool'不是类型'double'的子类型。

不知道为什么,虽然我试过添加容器包装组件,添加高度,添加灵活的盒子等......。

没有幸运


`import 'package:flutter/material.dart';

class SampleData {
  SampleData(this.title, [this.children = const <SizedBox>[]]);

  final String title;
  final List<SizedBox> children;
}

final List<SampleData> data = <SampleData>[
  SampleData("IT", [
        SizedBox(
          height: 300,
          width: 300,
          child: CustomScrollView(
            scrollDirection: Axis.horizontal,
            slivers: <Widget>[
              new SliverToBoxAdapter(
                child: Text('fesfefes'),
              ),
            ],
          ),
        ),
  ]),
];

class Branch extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test 123'),
      ),
      body: Container(
        width: 500,
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
          itemBuilder: (BuildContext context, int index) => Item(data[index]),
          itemCount: data.length,
        ),
      ),
    );
  }
}

// Displays one Entry. If the entry has children then it's displayed
// with an ExpansionTile.
class Item extends StatelessWidget {
  const Item(this.sample);

  final SampleData sample;

  Widget _buildTiles(SampleData root) {
    return SizedBox(
      width: 500,
      child: ExpansionTile(
        key: PageStorageKey<SampleData>(root),
        title: Text(root.title),
        children: root.children,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return _buildTiles(sample);
  }
}
`
flutter flutter-layout
1个回答
0
投票

你可以复制粘贴运行完整的代码吹你可以删除的代码

//key: PageStorageKey<SampleData>(root),

工作示范

enter image description here

全码

import 'package:flutter/material.dart';

class SampleData {
  SampleData(this.title, [this.children = const <SizedBox>[]]);

  final String title;
  final List<SizedBox> children;
}

final List<SampleData> data = <SampleData>[
  SampleData("IT", [
    SizedBox(
      height: 300,
      width: 300,
      child: CustomScrollView(
        scrollDirection: Axis.horizontal,
        slivers: <Widget>[
          new SliverToBoxAdapter(
            child: Text('fesfefes'),
          ),
        ],
      ),
    ),
  ]),
];

class Branch extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test 123'),
      ),
      body: Container(
        width: 500,
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
          itemBuilder: (BuildContext context, int index) => Item(data[index]),
          itemCount: data.length,
        ),
      ),
    );
  }
}

// Displays one Entry. If the entry has children then it's displayed
// with an ExpansionTile.
class Item extends StatelessWidget {
  const Item(this.sample);

  final SampleData sample;

  Widget _buildTiles(SampleData root) {
    return SizedBox(
      width: 500,
      child: ExpansionTile(
        //key: PageStorageKey<SampleData>(root),
        title: Text(root.title),
        children: root.children,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return _buildTiles(sample);
  }
}

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Branch(),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.