Skip to content

Instantly share code, notes, and snippets.

@ykmnkmi
Last active June 19, 2020 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykmnkmi/f556aff989807da626466df5a9fa4902 to your computer and use it in GitHub Desktop.
Save ykmnkmi/f556aff989807da626466df5a9fa4902 to your computer and use it in GitHub Desktop.
flutter transparent bg
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart' hide Draggable;
void main() {
runApp(App());
}
class App extends StatefulWidget {
const App({Key key}) : super(key: key);
@override
AppState createState() {
return AppState();
}
}
class AppState extends State<App> {
int counter;
@override
void initState() {
super.initState();
counter = 0;
}
@override
Widget build(BuildContext context) {
return Align(
child: SizedBox(
child: Draggable(
child: GestureDetector(
child: Opacity(
child: DecoratedBox(
child: Align(
child: Text(
'Taps: $counter',
style: TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 24.0,
shadows: <BoxShadow>[
BoxShadow(
blurRadius: 2.0,
color: Color(0xFFFFFFFF),
),
],
),
textDirection: TextDirection.ltr,
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(100.0)),
color: Color(0xFFFF0000),
boxShadow: <BoxShadow>[
BoxShadow(
blurRadius: 20.0,
color: Color(0xFFFF0000),
),
],
),
),
opacity: 0.5,
),
onTap: () {
setState(() {
counter++;
});
},
),
),
height: 200.0,
width: 200.0,
),
);
}
}
class Draggable extends StatelessWidget {
static const platformChannelDraggable = const MethodChannel('ykmnkmi.dev/draggable');
final Widget child;
Draggable({@required this.child});
@override
Widget build(BuildContext context) {
return GestureDetector(
child: child,
onPanStart: onPanStart,
onPanUpdate: onPanUpdate,
);
}
void onPanUpdate(DragUpdateDetails details) async {
await platformChannelDraggable.invokeMethod('onPanUpdate');
}
void onPanStart(DragStartDetails details) async {
await platformChannelDraggable.invokeMethod('onPanStart', {
'dx': details.globalPosition.dx,
'dy': details.globalPosition.dy,
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment