Skip to content

Instantly share code, notes, and snippets.

@ykmnkmi
Last active Jun 19, 2020
Embed
What would you like to do?
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