I have recently implemented the tap through functionality in my flutter app also I have previously written the code for the dragging functionality as well but when I implemented the tap through function in my code the dragging logic code does not work Can anyone help me through this problem?
Also I have used the Overlap Pop Up flutter package to do so that has a plus point of showing overlay even after the app is killed so can anyone guide me throughout this problem. I was struggling for more than 2 days but unable to solve this problem. Anyone Who solves my problem Thanks a Lot. 🙁
import 'package:overlay_pop_up/overlay_pop_up.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool isActive = false;
@override
void initState() {
super.initState();
overlayStatus();
}
Future<void> overlayStatus() async {
isActive = await OverlayPopUp.isActive();
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter overlay'),
backgroundColor: Colors.red[900],
),
body: Center(
child: MaterialButton(
onPressed: () async {
final permission = await OverlayPopUp.checkPermission();
if (permission) {
if (!await OverlayPopUp.isActive()) {
isActive = await OverlayPopUp.showOverlay(
width: 300,
height: 300,
closeWhenTapBackButton: false,
isDraggable: true,
backgroundBehavior: OverlayFlag.tapThrough,
);
setState(() {});
} else {
final result = await OverlayPopUp.closeOverlay();
setState(() {
isActive = (result == true) ? false : true;
});
}
} else {
await OverlayPopUp.requestPermission();
setState(() {});
}
},
color: Colors.red[900],
child: Text(
isActive ? 'Close overlay' : 'Show overlay',
style: TextStyle(color: Colors.white),
),
),
),
),
);
}
}
@pragma("vm:entry-point")
void overlayPopUp() {
WidgetsFlutterBinding.ensureInitialized();
runApp(
const MaterialApp(
debugShowCheckedModeBanner: false,
home: OverlayWidget(),
),
);
}
class OverlayWidget extends StatelessWidget {
const OverlayWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: IgnorePointer(
ignoring: false,
child: GestureDetector(
onTap: () {},
child: Stack(
children: [
Positioned(
left: 0,
top: 0,
child: Draggable(
child: Container(
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.3),
border: Border.all(color: Colors.red, width: 2.0),
shape: BoxShape.circle,
),
width: 100,
height: 100,
child: Center(
child: Text(
'•',
style: TextStyle(
fontSize: 40,
),
),
),
),
feedback: Material(),
onDraggableCanceled: (_, __) {}, // Allow dragging
),
),
],
),
),
),
);
}
}
Dipanshu Jangir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.