Comments (7)
Amigos pueden usar al comunicación mediante puertos Isolate.
Overlay********
En mi caso uso en overlay los siguiente atributos.
static const String _kPortName = 'overlay_port';
final _receivePort = ReceivePort();
static const String _kPortNameHome = 'home_port';
SendPort? homePort;
En initiState del overlay registro el puerto con el nombre;
IsolateNameServer.registerPortWithName(_receivePort.sendPort, _kPortName);
_receivePort.listen((message) {
//Aqui se recibe los mensajes del enviados del home al overlay
print("message overlay: $message");
});
En el evento onTop() de algun widget del overlay, trato de obtener el puerto del home o main, como ustedes lo usen.
homePort ??= IsolateNameServer.lookupPortByName(_kPortNameHome);
##para enviar mensaje del overlay al home usen, luego de haber registrado su homePort con la linea anterior.
homePort.send("texto"), homePort.send(list), homePort.send( { pro:"prop" } ), etc...
MAIN o Home o como lo usen****
Propiedades del main, o home, o como lo usen.
static const String _kPortName = 'overlay_port';
final _receivePort = ReceivePort();
static const String _kPortNameHome = 'home_port';
SendPort? homePort;
metodo initState
IsolateNameServer.registerPortWithName(_receivePort.sendPort, _kPortName);
_receivePort.listen((message) {
//Aqui se recibe los mensajes del enviados del overlay al home
print("message overlay: $message");
});
##para enviar mensaje del home al overlay usen lo siguiente:
overlayPort.send("texto"), overlayPort.send(list), overlayPort.send( { pro:"prop" } ), etc...
from flutter_overlay_window.
Hola @birnayt ,
Trata de colocar el codigo del widget en una funcion que se ejecute luego del initState
En mi caso, lo ejecuto en el onTap,
mapPort ??= IsolateNameServer.lookupPortByName(_kPortNameHome); mapPort?.send("test");
Esto debido a que puede que el puerto Home aún no esté registrado, por ello opte colocarlo en el onTap del widget.
Avisame cualquier novedad
from flutter_overlay_window.
First of all thank you very much @dorlanpabon!
I needed to close debug and start again for it to work. It seems that the reload is not enough. Now works!
from flutter_overlay_window.
from flutter_overlay_window.
You can use the method
await FlutterOverlayWindow.shareData("Hello from the other side");
and inside the overlay use
FlutterOverlayWindow.overlayListener.listen((event) {
log("Current Event: $event");
});
from flutter_overlay_window.
Hi @X-SLAYER I tried as you mentioned, but data is printing in the logs. But it was not updating in the UI. Please check the below code once and correct me
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
class MessangerChatHead extends StatefulWidget {
const MessangerChatHead({Key? key}) : super(key: key);
@override
State<MessangerChatHead> createState() => _MessangerChatHeadState();
}
class _MessangerChatHeadState extends State<MessangerChatHead> {
Color color = const Color(0xFFFF0C0C);
BoxShape shape = BoxShape.rectangle;
String data = '';
@override
void initState() {
super.initState();
FlutterOverlayWindow.overlayListener.listen((event) {
// setState(() {
data = event.toString();
log('Received Data : ${event.toString()}');
// });
});
}
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
elevation: 0.0,
child: GestureDetector(
onTap: () async {
if (shape == BoxShape.circle) {
await FlutterOverlayWindow.resizeOverlay(matchParent, matchParent);
setState(() {
shape = BoxShape.rectangle;
});
} else {
await FlutterOverlayWindow.resizeOverlay(150, 150);
setState(() {
shape = BoxShape.circle;
});
}
},
child: Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(color: color, shape: shape),
child: Center(
child: Text(data, style: const TextStyle(color: Colors.black, fontSize: 20),),
),
),
),
);
}
}
I tried with setState and without setState as well.
from flutter_overlay_window.
Hi @dorlanpabon, i tried to implement but it didn't work, I did what you say and also tried put kPortHomeName in registerPortWithName in home code.
In home:
IsolateNameServer.registerPortWithName(_receivePort.sendPort, _kPortNameHome);
_receivePort.listen((message) {
//Aqui se recibe los mensajes del enviados del overlay al home
print("message overlay: $message");
});
And in some onTap of widget overlay:
mapPort ??= IsolateNameServer.lookupPortByName(_kPortNameHome);
mapPort?.send("test");
I noticed that mapPort receives Sendport, but it still doesn't work.
from flutter_overlay_window.
Related Issues (20)
- Invalid file path for libcolorx-loader.so Error while rendering model viewer widget inside overlay.
- Error on demo code
- Overlay window doesn't work in apk release mode
- Android API 33 crashes HOT 3
- Values in resizeOverlay not coherent with values in showOverlay HOT 2
- Crached when close overlay in android 12 HOT 5
- Wrong size when switching between portrait and landscape mode.
- Can flutter_web be used in Windows?
- TextFormField not supported HOT 1
- Not able to add any other plugin into the overlay screen
- Not able to receive message from flutter_background_service HOT 1
- when call Function showOverlay() nothing action HOT 2
- add ios support HOT 5
- Unable to create service flutter.overlay.window.flutter_overlay_window.OverlayService: HOT 4
- Add support for android API 34 HOT 1
- Height doesn't account for status bar
- Use of `FlutterEngineGroup` instead of simply using `FlutterEngine` HOT 1
- Overlay stops sending messages to UI when it's turned on after previously being closed after app termination
- Unable to create multiple overlay window. HOT 4
- Please add more flags to show when phone is looked HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_overlay_window.