Flutter draggable ListItem - 找不到材质小部件

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

在没有拖拽ListView的任何烹饪书示例的情况下,我正在尝试创建自己的但是在尝试拖动行时我得到错误:找不到材质小部件。我已经尝试在容器中包装ListTiles但似乎总是得到相同的错误。

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final title = 'Basic List';

    var tile1 = new ListTile(
      leading: new Icon(Icons.photo),
      title: new Text('Row 1'),
    );

    var tile2 = new ListTile(
      leading: new Icon(Icons.photo),
      title: new Text('Row 2'),
    );

    var tile3 = new ListTile(
      leading: new Icon(Icons.photo),
      title: new Text('Row 3'),
    );

    return new MaterialApp(
      title: title,
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text(title),
        ),
        body: new ListView(
            children: [
              new Draggable(child: tile1, feedback: tile1),
              new Draggable(child: tile2, feedback: tile2),
              new Draggable(child: tile3, feedback: tile3),
            ],
        ),
      ),
    );
  }
}
flutter
1个回答
1
投票

也许,不是最好的解决方案,但它适合我

Draggable(
  axis: Axis.vertical,
  maxSimultaneousDrags: 1,
  child: tile,
  childWhenDragging: Opacity(
    opacity: 0.5,
    child: tile,
  ),
  feedback: Material(
    child: ConstrainedBox(
      constraints:
          BoxConstraints(maxWidth: MediaQuery.of(context).size.width),
      child: tile,
    ),
    elevation: 4.0,
  ),

我在ConstrainedBox包裹瓷砖,宽度从屏幕尺寸。

© www.soinside.com 2019 - 2024. All rights reserved.