Flutter page drag button DraggableFloatingActionButton

Climbers aiming for the top will not be intoxicated by a certain footprint along the way. In the world of code farmers, the beautiful application experience comes from the programmer's handling of details and the realm of self-requirements. Young people are also busy One of the busy code farmers, every day and every week, will leave some footprints. It is the content of these creations. There is a kind of persistence. I don’t know why. If you are confused, you might as well take a look at the track of the code farmers.

If you are interested, you can follow the public account biglead to get the latest learning materials.


Renderings of this article
insert image description here

1 The first step is to add plugin dependencies

shake_animation_widget: ^3.0.3
2 use in code
class Exam223HomePage extends StatefulWidget {
    
    
  const Exam223HomePage({
    
    Key? key}) : super(key: key);

  @override
  State<Exam223HomePage> createState() => _Exam223HomePageState();
}



class _Exam223HomePageState extends State<Exam223HomePage> {
    
    
  //Stack使用的Key
  final GlobalKey _parentKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    
    
    return Scaffold(
      body: SizedBox(
        width: double.infinity,
        height: double.infinity,
        child: Stack(
          key: _parentKey,
          children: [
            Container(color: Colors.blueGrey),

            DraggableFloatingActionButton(
              child: Container(
                width: 60,
                height: 60,
                decoration: const ShapeDecoration(
                  shape: CircleBorder(),
                  color: Colors.white,
                ),
                child: const Icon(Icons.add),
              ),
              initialOffset: const Offset(120, 70),
              parentKey: _parentKey,
              onPressed: () {
    
    },
            ),
          ],
        ),
      ),
    );
  }
}

If you are confused, you might as well come here to share every day, and then accumulate
more Widget applications. The editor has summarized them in the book.


insert image description here


おすすめ

転載: blog.csdn.net/zl18603543572/article/details/123313641