Last updated:
0 purchases
external display
external_display #
Flutter plugin support for connecting to external displays through wired or wireless connections
Getting Started #
External display entry point externalDisplayMain #
@pragma('vm:entry-point')
void externalDisplayMain() {
}
copied to clipboard
Create externalDisplay variables #
ExternalDisplay externalDisplay = ExternalDisplay();
copied to clipboard
Monitor external monitor plugging and unplugging #
externalDisplay.addListener(onDisplayChange);
copied to clipboard
Cancel monitoring of external monitor #
externalDisplay.removeListener(onDisplayChange);
copied to clipboard
Get the plugging status #
externalDisplay.isPlugging
copied to clipboard
Get the external monitor resolution #
externalDisplay.resolution
copied to clipboard
Connecting the monitor #
await externalDisplay.connect();
copied to clipboard
or
await externalDisplay.connect(routeName: name);
copied to clipboard
Transfer parameters to external display #
await externalDisplay.transferParameters(action: actionName, value: parameters);
copied to clipboard
external view receive parameters #
include receive_parameters.dart #
import 'package:external_display/receive_parameters.dart';
copied to clipboard
Create receiveParameters variables #
ReceiveParameters receiveParameters = ReceiveParameters();
copied to clipboard
Add listener #
receiveParameters.addListener(({required action, value}) {
print(action);
print(value);
});
copied to clipboard
Remove listener
receiveParameters.removeListener(receive);
copied to clipboard
example #
import 'package:flutter/material.dart';
import 'package:external_display/external_display.dart';
void main() {
runApp(const MyApp());
}
@pragma('vm:entry-point')
void externalDisplayMain() {
runApp(const MaterialApp(
home: externalView(),
));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Home()
);
}
}
class externalView extends StatelessWidget {
const externalView({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Text('This is external view.')),
);
}
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
ExternalDisplay externalDisplay = ExternalDisplay();
String state = "Unplug";
String resolution = "";
onDisplayChange(connecting) {
if (connecting) {
setState(() {
state = "Plug";
});
} else {
setState(() {
state = "Unplug";
resolution = "";
});
}
}
@override
void initState() {
super.initState();
externalDisplay.addListener(onDisplayChange);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('External Display Example'),
),
body: Container(
color: Colors.white,
child: Column(
children: [
Container(
height: 100,
alignment: Alignment.center,
child: Text("External Monitor is $state")
),
Container(
height: 100,
alignment: Alignment.center,
child: TextButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.blue),
),
onPressed: () async {
await externalDisplay.connect();
setState(() {
resolution = "width:${externalDisplay.resolution?.width}px, height:${externalDisplay.resolution?.height}px";
});
},
child: const Text("Connect")
),
),
Container(
height: 100,
alignment: Alignment.center,
child: Text(resolution)
)
]
),
)
);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.