リスト 4.52_cf with print();


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

void main() {
  return runApp(TestPage());
}

//リスト4.52_cf with print();
class TestPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  String text = '';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Draggable',
      home: Scaffold(
        appBar: AppBar(title: Text('Draggable')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            mainAxisSize: MainAxisSize.min,
            children: [
              Draggable(
                data: 'data',
                feedback: Icon(Icons.run_circle_outlined, size: 100),
                childWhenDragging: Icon(Icons.play_arrow, size: 100),
                onDraggableCanceled: (_, offset) {},
                child: Icon(Icons.stop, size: 100)
              ),
              DragTarget(
                builder: (context, candidateData, rejectedData) {
                  return Container(
                    width: 200,
                    height: 150,
                    color: Colors.grey
                  );
                },
                onWillAccept: (String? data) {
                  setState(() {
                    text = 'onWillAccept';
                    print('onWillAccept');
                  });
                  return true;
                },
                onLeave: (String? data) {
                  setState(() {
                    text = 'onLeave';
                    print('onLeave');
                  });
                },
                onAccept: (String data) {
                  setState(() {
                    text = 'onAccept';
                    print('onAccept');
                  });
                }
              ),
              Text(text)
            ]
          )
        )
      )
    );
  }
}