Skip to content

Commit

Permalink
Merge pull request #12 from EbramTawfik/iOS
Browse files Browse the repository at this point in the history
Complete implementation for iOS and adding changes to the example
  • Loading branch information
VNAPNIC authored Aug 18, 2021
2 parents 2ee2749 + 903977f commit 14021d1
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 75 deletions.
7 changes: 6 additions & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import UIKit
import Flutter

import presentation_displays
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
SwiftPresentationDisplaysPlugin.controllerAdded = controllerAdded
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func controllerAdded(controller:FlutterViewController)
{
GeneratedPluginRegistrant.register(with: controller)
}
}
216 changes: 178 additions & 38 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Button extends StatelessWidget {
onPressed: function,
child: Text(
title,
style: TextStyle(fontSize: 40),
style: TextStyle(fontSize: 25),
),
),
);
Expand All @@ -63,54 +63,194 @@ class _DisplayManagerScreenState extends State<DisplayManagerScreen> {
DisplayManager displayManager = DisplayManager();
List<Display?> displays = [];

TextEditingController _indexToShareController = TextEditingController();
TextEditingController _dataToTransferController = TextEditingController();

TextEditingController _nameOfIdController = TextEditingController();
String _nameOfId = "";
TextEditingController _nameOfIndexController = TextEditingController();
String _nameOfIndex = "";

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Wrap(
alignment: WrapAlignment.center,
children: <Widget>[
Button("Get Displays", () async {
final values = await displayManager.getDisplays();
print(values);
displays.clear();
displays.addAll(values!);
print(displays);
}),
Button("Show presentation", () async {
displayManager.showSecondaryDisplay(
displayId: displays.length > 0
? displays[1]?.displayId ?? -1
: -1,
routerName: "presentation");
}),
Button("NameByDisplayId", () async {
final value = await displayManager
.getNameByDisplayId(displays[1]?.displayId ?? -1);
print(value);
}),
Button("NameByIndex", () async {
final value = await displayManager.getNameByIndex(1);
print(value);
}),
Button("TransferData", () async {
final value = await displayManager
.transferDataToPresentation("test transfer data");
print(value);
})
],
),
],
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
_getDisplays(),
_showPresentation(),
_transferData(),
_getDisplayeById(),
_getDisplayByIndex(),
],
),
),
),
);
}

Widget _getDisplays() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Button("Get Displays", () async {
final values = await displayManager.getDisplays();
print(values);
displays.clear();

setState(() {
displays.addAll(values!);
});
print(displays);
}),
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
padding: const EdgeInsets.all(8),
itemCount: displays.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
child: Center(
child: Text(
' ${displays[index]?.displayId} ${displays[index]?.name}')),
);
}),
Divider()
],
);
}

Widget _showPresentation() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _indexToShareController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Index to share screen',
),
),
),
Button("Show presentation", () async {
int? index = int.tryParse(_indexToShareController.text);
if (index != null && index < displays.length) {
displayManager.showSecondaryDisplay(
displayId:
displays.length > 0 ? displays[index]?.displayId ?? -1 : 1,
routerName: "presentation");
}
}),
Divider(),
],
);
}

Widget _transferData() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _dataToTransferController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Data to transfer',
),
),
),
Button("TransferData", () async {
String data = _dataToTransferController.text;

final value = await displayManager.transferDataToPresentation(data);
print(value);
}),
Divider(),
],
);
}

Widget _getDisplayeById() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _nameOfIdController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Id',
),
),
),
Button("NameByDisplayId", () async {
int? id = int.tryParse(_nameOfIdController.text);
if (id != null) {
final value = await displayManager
.getNameByDisplayId(displays[id]?.displayId ?? -1);
print(value);
setState(() {
_nameOfId = value ?? "";
});
}
}),
Container(
height: 50,
child: Center(child: Text(_nameOfId)),
),
Divider(),
],
);
}

Widget _getDisplayByIndex() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: _nameOfIndexController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Index',
),
),
),
Button("NameByIndex", () async {
int? index = int.tryParse(_nameOfIndexController.text);
if (index != null) {
final value = await displayManager.getNameByIndex(index);
print(value);
setState(() {
_nameOfIndex = value ?? "";
});
}
}),
Container(
height: 50,
child: Center(child: Text(_nameOfIndex)),
),
Divider(),
],
);
}
}

/// UI of Presentation display
Expand Down
Loading

0 comments on commit 14021d1

Please sign in to comment.