remove boilerplate

This commit is contained in:
Prerak Mann 2019-05-10 13:03:41 +05:30
parent 7f1c9c9e8c
commit 59cb4ba91d
7 changed files with 38 additions and 59 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
.pub/ .pub/
build/ build/
.idea/

View File

@ -1,14 +1,18 @@
# nearby_connections # nearby_connections
A new Flutter plugin. An android flutter plugin for the Nearby Connections API
## Getting Started ## Getting Started
This project is a starting point for a Flutter ### Set Permissions
[plug-in package](https://flutter.dev/developing-packages/), ```xml
a specialized package that includes platform-specific implementation code for <!-- Required for Nearby Connections -->
Android and/or iOS. <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
```
Since ACCESS_FINE_LOCATION is considered to be dangerous system permissions, in addition to adding them to your manifest, you must request these permissions at runtime.
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

View File

@ -31,4 +31,7 @@ android {
lintOptions { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
} }
dependencies{
api 'com.google.android.gms:play-services-nearby:16.0.0'
}
} }

View File

@ -6,9 +6,13 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.plugin.common.PluginRegistry.Registrar;
/** NearbyConnectionsPlugin */ /**
* NearbyConnectionsPlugin
*/
public class NearbyConnectionsPlugin implements MethodCallHandler { public class NearbyConnectionsPlugin implements MethodCallHandler {
/** Plugin registration. */ /**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) { public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "nearby_connections"); final MethodChannel channel = new MethodChannel(registrar.messenger(), "nearby_connections");
channel.setMethodCallHandler(new NearbyConnectionsPlugin()); channel.setMethodCallHandler(new NearbyConnectionsPlugin());
@ -16,10 +20,12 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
@Override @Override
public void onMethodCall(MethodCall call, Result result) { public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE); switch (call.method) {
} else {
default:
result.notImplemented(); result.notImplemented();
} }
} }
} }

View File

@ -12,34 +12,6 @@ class MyApp extends StatefulWidget {
} }
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await NearbyConnections.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
@ -48,7 +20,7 @@ class _MyAppState extends State<MyApp> {
title: const Text('Plugin example app'), title: const Text('Plugin example app'),
), ),
body: Center( body: Center(
child: Text('Running on: $_platformVersion\n'), child: Text('Welcome'),
), ),
), ),
); );

View File

@ -6,8 +6,5 @@ class NearbyConnections {
static const MethodChannel _channel = static const MethodChannel _channel =
const MethodChannel('nearby_connections'); const MethodChannel('nearby_connections');
static Future<String> get platformVersion async {
final String version = await _channel.invokeMethod('getPlatformVersion');
return version;
}
} }

View File

@ -14,8 +14,4 @@ void main() {
tearDown(() { tearDown(() {
channel.setMockMethodCallHandler(null); channel.setMockMethodCallHandler(null);
}); });
test('getPlatformVersion', () async {
expect(await NearbyConnections.platformVersion, '42');
});
} }