Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't display my data on the overlay window. #115

Open
Tr0y2ooo opened this issue May 27, 2024 · 3 comments
Open

I can't display my data on the overlay window. #115

Tr0y2ooo opened this issue May 27, 2024 · 3 comments

Comments

@Tr0y2ooo
Copy link

I have wrote homepage.dart,there's a button,I add a function in onPress event.
trailing: IconButton(
icon: const Icon(Icons.map),
onPressed: () async {
_launchMapsLauncher(
_selectedNavOp, address, latitude, longitude);
_openFloatingWindow(context);
///////////////////////////////////////////////////////////////////////////////////
void _openFloatingWindow (BuildContext context) async{
if (await FlutterOverlayWindow.isActive()) return;
await FlutterOverlayWindow.showOverlay(
enableDrag: true,
overlayTitle: _selectedAddress!,
overlayContent: 'Overlay Enabled',
flag: OverlayFlag.defaultFlag,
visibility: NotificationVisibility.visibilityPublic,
positionGravity: PositionGravity.auto,
height: (MediaQuery.of(context).size.height * 0.6).toInt(),
width: WindowSize.matchParent,
startPosition: const OverlayPosition(0, -259),
);
}
the Overlaywindow shows context of true_caller_overlay not the context i except to
true_caller_overlay.dart
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
import '../home_page.dart';

class TrueCallerOverlay extends StatefulWidget {
final String title;

const TrueCallerOverlay({Key? key, required this.title}) : super(key: key);

@OverRide
State createState() => _TrueCallerOverlayState();
}

class _TrueCallerOverlayState extends State {

@OverRide
void initState() {
super.initState();
}

@OverRide
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 5.0),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.black, // 將背景顏色設置為黑色
borderRadius: BorderRadius.circular(12.0),
),
child: GestureDetector(
onTap: () {
FlutterOverlayWindow.getOverlayPosition().then((value) {
log("Overlay Position: $value");
});
},
child: Stack(
children: [
Column(
children: [
ListTile(
leading: Container(
height: 80.0,
width: 80.0,
),
title: const Text(
"aaaaaa",
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold , color: Colors.white),
),
),
],
),
Positioned(
top: 0,
right: 0,
child: IconButton(
onPressed: () async {
await FlutterOverlayWindow.closeOverlay();
},
icon: const Icon(
Icons.close,
color: Colors.white,
),
),
),
],
),
),
),
),
);
}
}
and my main.dart
import 'dart:async';
import 'package:v2_0/auth/login_screen.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
import '../overlays/true_caller_overlay.dart';

Future main() async {
WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);

runApp(const MyApp());
}
@pragma("vm:entry-point")
void overlayMain() {
WidgetsFlutterBinding.ensureInitialized();
runApp(
const MaterialApp(
debugShowCheckedModeBanner: false,
home: TrueCallerOverlay(title: '123',),
),
);
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@OverRide
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false, home: LoginScreen());
}
}

@chinmay4github1987
Copy link

Same here not able to send the data to the overlay window

@Ngochiendev
Copy link

same issue :( Have you found the solution yet?

@hello-world0321
Copy link

i might have a solution for the FlutterOverlayWindow package since im using the same one too

First
add the dependency 'flutter_overlay_window: ^0.4.4' to your pubspec.yaml

Second
import the package 'import 'package:flutter_overlay_window/flutter_overlay_window.dart';'

Third
this is my function of the overlay window
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ home_page.dart
OverlayPosition? storedPosition;

Future _launchOverlayWindow(String? isDarkModeString,
String? selectedAddress, String? selectedFlavors) async {
if (!_permissionGranted!) {
_permissionGranted =
await FlutterOverlayWindow.requestPermission() ?? false;
}

if (_permissionGranted!) {
  FlutterOverlayWindow.closeOverlay();

  storedPosition = await FlutterOverlayWindow.getOverlayPosition();
  sendData(isDarkModeString, selectedAddress, selectedFlavors);

  await FlutterOverlayWindow.showOverlay(
    visibility: NotificationVisibility.visibilityPublic,
    flag: OverlayFlag.defaultFlag,
    width: _screenWidthInt!,
    height: _screenHeightInt!,
    enableDrag: true,
    positionGravity: PositionGravity.none,
    startPosition: storedPosition ?? OverlayPosition(0, 0),
  );
}

}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\true_caller.dart
void sendData(String? isDarkModeString, String? address, String? flavors) {
final data =
'{"isDarkModeString": "$isDarkModeString", "address": "$address", "flavors": "$flavors"}';
FlutterOverlayWindow.shareData(data);
}

@OverRide
void initState() {
super.initState();
FlutterOverlayWindow.overlayListener.listen((event) {
final parsedData = parseEvent(event);
setState(() {
isDarkModeString = parsedData['isDarkModeString'] ?? '';
address = parsedData['address'] ?? '';
flavors = parsedData['flavors'] ?? '';
isDarkModeBool = isDarkModeString.toLowerCase() == 'true';
});
});
}

Map<String, dynamic> parseEvent(String event) {
try {
final Map<String, dynamic> data = jsonDecode(event);
return {
'isDarkModeString': data['isDarkModeString'] as String,
'address': data['address'] as String,
'flavors': data['flavors'] as String,
};
} catch (e) {
log("Error parsing event data: $e");
return {};
}
}
hope you might find this helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants