Я создаю простой listView во Flutter, где «ячейки» - это простые карты с установленным полем. При отклонении этих карт «поле» закрывает недопустимый фон, что приводит к некрасивому дизайну. Я создал пример приложения, чтобы продемонстрировать эту проблему:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
// MyApp is a StatefulWidget. This allows updating the state of the
// widget when an item is removed.
class MyApp extends StatefulWidget {
MyApp({Key key}) : super(key: key);
@override
MyAppState createState() {
return MyAppState();
}
}
class MyAppState extends State<MyApp> {
final items = List<String>.generate(20, (i) => "Item ${i + 1}");
@override
Widget build(BuildContext context) {
final title = 'Dismissing Items';
return MaterialApp(
title: title,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return Dismissible(
// Each Dismissible must contain a Key. Keys allow Flutter to
// uniquely identify widgets.
key: Key(item),
// Provide a function that tells the app
// what to do after an item has been swiped away.
onDismissed: (direction) {
// Remove the item from the data source.
setState(() {
items.removeAt(index);
});
// Then show a snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
// Show a red background as the item is swiped away.
background: Container(color: Colors.red),
child: Card(color: Colors.blue, margin: EdgeInsets.all(9), child: ListTile(title: Text('$item'))),
);
},
),
),
);
}
}
При отклонении получается следующий дизайн: Изображение Карты, закрывающее фон запрещенного виджета
Также нельзя положить разрешенное на карту, так как тогда вы не смахиваете карту. Это ошибка Flutter или есть более простое решение?