Created
July 27, 2020 05:56
-
-
Save iamSahdeep/855f0e2274732ec3b0b6cd65b24e1ca4 to your computer and use it in GitHub Desktop.
Simple example to convert your widget into the Mouse Cursor in Flutter Web
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/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp( | |
MaterialApp( | |
theme: ThemeData(scaffoldBackgroundColor: darkBlue), | |
home: MyWidget(), | |
), | |
); | |
} | |
class MyWidget extends StatefulWidget { | |
@override | |
_MyWidgetState createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
Offset pointer = Offset.zero; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: MouseRegion( | |
cursor: SystemMouseCursors.none, | |
onHover: (eve) { | |
setState(() { | |
pointer = eve.position; | |
}); | |
}, | |
child: Stack( | |
children: [ | |
AnimatedPositioned( | |
duration: const Duration(milliseconds: 500), | |
left: pointer.dx - 100, | |
top: pointer.dy - 100, | |
child: Container( | |
height: 200, | |
width: 200, | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.all(Radius.circular(100)), | |
border: Border.all( | |
width: 4, | |
color: Colors.white, | |
style: BorderStyle.solid)), | |
), | |
), | |
], | |
)), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment