Created
December 12, 2021 23:20
-
-
Save Lootwig/909fcfbd3bb0df0102ed322236b3ce81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const MaterialApp(home:Scaffold(body: Center(child:A())))); | |
class A extends StatelessWidget { | |
const A({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final from = [Object()]; | |
final to = [Object(), Object()]; | |
return Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: [ | |
const SizedBox(height: 150), | |
const Text('From'), | |
const SizedBox(height: 15), | |
DragTarget<int>( | |
builder: (_, candidateData, __) { | |
return B(items: from.map((item) => item.hashCode)); | |
}, | |
), | |
const SizedBox(height: 15), | |
const Text('To'), | |
const SizedBox(height: 15), | |
DragTarget<int>( | |
builder: (_, candidateData, __) { | |
return B(items: to.map((item) => item.hashCode)); | |
}, | |
), | |
], | |
); | |
} | |
} | |
class B extends StatelessWidget { | |
final Iterable<int> items; | |
const B({Key? key, required this.items}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedCrossFade( | |
duration: const Duration(milliseconds: 200), | |
crossFadeState: | |
items.isEmpty ? CrossFadeState.showFirst : CrossFadeState.showSecond, | |
firstChild: const SizedBox(), | |
secondChild: Wrap( | |
children: [ | |
...items.map((number) { | |
final widget = Text(number.toString()); | |
return Draggable<int>( | |
feedback: widget, | |
childWhenDragging: Padding( | |
padding: const EdgeInsets.only(left: 54, top: 15), | |
child: Opacity(opacity: 0, child: Text(number.toString())), | |
), | |
data: number, | |
child: widget, | |
); | |
}), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment