Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何更改颤振中的布局_Flutter_Flutter Layout - Fatal编程技术网

Flutter 如何更改颤振中的布局

Flutter 如何更改颤振中的布局,flutter,flutter-layout,Flutter,Flutter Layout,我一直在尝试设计我的扩展文件的布局,就像下面的设计一样,但我不知道如何更改布局。有没有关于如何更改边框半径、更改背景颜色以及在彼此之间留出间隙的建议 我尝试在每个容器中添加BoxEdition,但该样式仅适用于外部,而不适用于每个扩展文件 import 'package:flutter/material.dart'; class MyReoderWidget extends StatelessWidget { @override Widget build(BuildContext co

我一直在尝试设计我的扩展文件的布局,就像下面的设计一样,但我不知道如何更改布局。有没有关于如何更改边框半径、更改背景颜色以及在彼此之间留出间隙的建议

我尝试在每个容器中添加BoxEdition,但该样式仅适用于外部,而不适用于每个扩展文件

import 'package:flutter/material.dart';

class MyReoderWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ReorderItems(topTen: ['j']);
  }
}
class DataHolder {
  List<String> parentKeys;

  Map<String, List<String>> childMap;

  DataHolder._privateConstructor();

  static final DataHolder _dataHolder = DataHolder._privateConstructor();

  static DataHolder get instance => _dataHolder;

  factory DataHolder.initialize({@required parentKeys}) {
    _dataHolder.parentKeys = parentKeys;
    _dataHolder.childMap = {};
    for (String key in parentKeys) {
      _dataHolder.childMap.putIfAbsent(

    }
    return _dataHolder;
  }
}

class ReorderItems extends StatefulWidget {
  final List<String> topTen;
  ReorderItems({this.topTen});
  @override
  _ReorderItemsState createState() => _ReorderItemsState();
}

class _ReorderItemsState extends State<ReorderItems> {
  @override
  void initState() {
    super.initState();
    // initialize the children for the Expansion tile
    // This initialization can be replaced with any logic like network fetch or something else.
    DataHolder.initialize(parentKeys: widget.topTen);
  }

  @override
  Widget build(BuildContext context) {
    return PrimaryScrollController(
      key: ValueKey(widget.topTen.toString()),
      controller: ScrollController(),
      child: Container(
        decoration: BoxDecoration(),
        child: ReorderableListView(
          onReorder: onReorder,
          children: getListItem(),
        ),
      ),
    );
  }

  List<ExpansionTile> getListItem() => DataHolder.instance.parentKeys
      .asMap()
      .map((index, item) => MapEntry(index, buildTenableListTile(item, index)))
      .values
      .toList();

  ExpansionTile buildTenableListTile(String mapKey, int index) => ExpansionTile(
        key: ValueKey(mapKey),
        title: Text(mapKey),
        leading: Icon(Icons.list),
        children: [
          Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(20))
            ),
            key: ValueKey('$mapKey$index'),
            height: 200,
            child: Container(
              padding: EdgeInsets.only(left: 30.0),
              child: ReorderList(
                parentMapKey: mapKey,
              ),
            ),
          ),
        ],
      );

  void onReorder(int oldIndex, int newIndex) {
    if (newIndex > oldIndex) {
      newIndex -= 1;
    }
    setState(() {
      String game = widget.topTen[oldIndex];
      DataHolder.instance.parentKeys.removeAt(oldIndex);
      DataHolder.instance.parentKeys.insert(newIndex, game);
    });
  }
}

class ReorderList extends StatefulWidget {
  final String parentMapKey;
  ReorderList({this.parentMapKey});
  @override
  _ReorderListState createState() => _ReorderListState();
}

class _ReorderListState extends State<ReorderList> {
  @override
  Widget build(BuildContext context) {
    return PrimaryScrollController(
      controller: ScrollController(),
      child: ReorderableListView(
        // scrollController: ScrollController(),
        onReorder: onReorder,
        children: DataHolder.instance.childMap[widget.parentMapKey]
            .map(
              (String child) => Container(
                child: ListTile(
                  key: ValueKey(child),
                  leading: Icon(Icons.list),
                  title: Text(child),
                ),
              ),
            )
            .toList(),
      ),
    );
  }

  void onReorder(int oldIndex, int newIndex) {
    if (newIndex > oldIndex) {
      newIndex -= 1;
    }
    List<String> children = DataHolder.instance.childMap[widget.parentMapKey];
    String game = children[oldIndex];
    children.removeAt(oldIndex);
    children.insert(newIndex, game);
    DataHolder.instance.childMap[widget.parentMapKey] = children;
    // Need to set state to rebuild the children.
    setState(() {});
  }
}
导入“包装:颤振/材料.省道”;
类MyReoderWidget扩展了无状态Widget{
@凌驾
小部件构建(构建上下文){
返回重新排序项(前十名:['j']);
}
}
类数据持有者{
列出父密钥;
地图儿童地图;
数据持有者。_privateConstructor();
静态最终数据持有者_DataHolder=数据持有者。_privateConstructor();
静态数据持有者获取实例=>\u数据持有者;
工厂数据持有者。初始化({@required parentKeys}){
_dataHolder.parentkey=parentkey;
_dataHolder.childMap={};
for(parentKeys中的字符串键){
_dataHolder.childMap.putIfAbsent(
}
返回数据持有者;
}
}
类重新排序项扩展StatefulWidget{
最终排名前十名;
重新排序项({this.topTen});
@凌驾
_ReorderItemsState createState()=>_ReorderItemsState();
}
类_ReorderItemsState扩展状态{
@凌驾
void initState(){
super.initState();
//初始化扩展磁贴的子级
//这种初始化可以用任何逻辑(如网络获取或其他)来代替。
DataHolder.initialize(parentkey:widget.topTen);
}
@凌驾
小部件构建(构建上下文){
返回主滚动控制器(
key:ValueKey(widget.topTen.toString()),
控制器:ScrollController(),
子:容器(
装饰:BoxDecoration(),
子:ReorderableListView(
onReorder:onReorder,
子项:getListItem(),
),
),
);
}
列出getListItem()=>DataHolder.instance.parentKeys
.asMap()
.map((索引,项)=>MapEntry(索引,buildTenableListTile(项,索引)))
价值观
.toList();
ExpansionFile buildTenableListTile(字符串映射键,int索引)=>ExpansionFile(
键:ValueKey(映射键),
标题:文本(地图键),
前导:图标(Icons.list),
儿童:[
容器(
装饰:盒子装饰(
边界半径:边界半径。全部(半径。圆形(20))
),
key:ValueKey(“$mapKey$index”),
身高:200,
子:容器(
填充:仅限边缘设置(左:30.0),
子:重新排序列表(
parentMapKey:mapKey,
),
),
),
],
);
void onReorder(int oldIndex,int newIndex){
如果(新建索引>旧索引){
newIndex-=1;
}
设置状态(){
字符串游戏=widget.topTen[oldIndex];
DataHolder.instance.parentKeys.removeAt(oldIndex);
DataHolder.instance.parentKeys.insert(newIndex,game);
});
}
}
类ReorderList扩展了StatefulWidget{
最后一个字符串parentMapKey;
重新排序列表({this.parentMapKey});
@凌驾
_ReorderListState createState()=>\u ReorderListState();
}
类_ReorderListState扩展状态{
@凌驾
小部件构建(构建上下文){
返回主滚动控制器(
控制器:ScrollController(),
子:ReorderableListView(
//scrollController:scrollController(),
onReorder:onReorder,
子项:DataHolder.instance.childMap[widget.parentMapKey]
.地图(
(字符串子项)=>容器(
孩子:ListTile(
key:ValueKey(子项),
前导:图标(Icons.list),
标题:文本(儿童),
),
),
)
.toList(),
),
);
}
void onReorder(int oldIndex,int newIndex){
如果(新建索引>旧索引){
newIndex-=1;
}
List children=DataHolder.instance.childMap[widget.parentMapKey];
弦乐游戏=儿童[旧索引];
children.removeAt(旧索引);
插入(新索引,游戏);
DataHolder.instance.childMap[widget.parentMapKey]=子对象;
//需要设置状态以重建子级。
setState((){});
}
}

您可以使用自定义的可扩展容器来执行此操作。

导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振日历”,
主题:主题数据(
主样本:颜色。灰色,
),
debugShowCheckedModeBanner:false,
家:材料(
子项:MyReoderWidget(),
),
);
}
}
类自定义模型{
字符串标题;
布尔展开;
列出分项;
CustomModel({this.title,this.subItems,this.isExpanded=false});
}
类MyReoderWidget扩展了StatefulWidget{
@凌驾
_MyReoderWidgetState createState()=>\u MyReoderWidgetState();
}
类_MyReoderWidgetState扩展状态{
列出清单项目;
@凌驾
void initState(){
super.initState();
listItems=List();
添加(自定义模型)(
标题:“应用程序名称1”,子项:[“卡名称1”,“卡名称2”]);
添加(自定义模型)(
标题:“应用程序名称2”,子项:[“卡名称3”,“卡名称4”]);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.black,
正文:ListView(
子项:列表项
.map((模型)=>新填充(
填充:仅限边缘设置(
底部:10,
),
子:ExpandableCardContainer(
isExpanded:model.isExpanded,
collapsedChild:createHeaderCard(模型),
expandedChild:列(
儿童:[
填充物(
衬垫