chore: generate template (#19)
This commit is contained in:
committed by
GitHub
parent
1eba29b7ca
commit
bb943d2f71
@@ -0,0 +1,7 @@
|
||||
.DS_Store
|
||||
.dart_tool/
|
||||
|
||||
.packages
|
||||
.pub/
|
||||
|
||||
build/
|
||||
@@ -0,0 +1,3 @@
|
||||
# 0.1.0+1
|
||||
|
||||
- Initial release of this plugin.
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Very Good Ventures
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,14 @@
|
||||
# {{project_name.snakeCase()}}_linux
|
||||
|
||||
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
|
||||
|
||||
The linux implementation of `{{project_name.snakeCase()}}`.
|
||||
|
||||
## Usage
|
||||
|
||||
This package is [endorsed][endorsed_link], which means you can simply use `{{project_name.snakeCase()}}`
|
||||
normally. This package will be automatically included in your app when you do.
|
||||
|
||||
[endorsed_link]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin
|
||||
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
|
||||
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
|
||||
@@ -0,0 +1 @@
|
||||
include: package:very_good_analysis/analysis_options.2.4.0.yaml
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2022, Very Good Ventures
|
||||
// https://verygood.ventures
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:{{project_name.snakeCase()}}_platform_interface/{{project_name.snakeCase()}}_platform_interface.dart';
|
||||
|
||||
/// The Linux implementation of [{{project_name.pascalCase()}}Platform].
|
||||
class {{project_name.pascalCase()}}Linux extends {{project_name.pascalCase()}}Platform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
final methodChannel = const MethodChannel('{{project_name.snakeCase()}}_linux');
|
||||
|
||||
/// Registers this class as the default instance of [{{project_name.pascalCase()}}Platform]
|
||||
static void registerWith() {
|
||||
{{project_name.pascalCase()}}Platform.instance = {{project_name.pascalCase()}}Linux();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> getPlatformName() {
|
||||
return methodChannel.invokeMethod<String>('getPlatformName');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2022, Very Good Ventures
|
||||
// https://verygood.ventures
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
export 'src/{{project_name.snakeCase()}}_linux.dart';
|
||||
@@ -0,0 +1,17 @@
|
||||
flutter/
|
||||
|
||||
# Visual Studio user-specific files.
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# Visual Studio build-related files.
|
||||
x64/
|
||||
x86/
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
@@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
set(PROJECT_NAME "{{project_name.snakeCase()}}_linux")
|
||||
project(${PROJECT_NAME} LANGUAGES CXX)
|
||||
|
||||
set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
|
||||
|
||||
list(APPEND PLUGIN_SOURCES
|
||||
"{{project_name.snakeCase()}}_linux_plugin.cc"
|
||||
)
|
||||
|
||||
add_library(${PLUGIN_NAME} SHARED
|
||||
${PLUGIN_SOURCES}
|
||||
)
|
||||
apply_standard_settings(${PLUGIN_NAME})
|
||||
set_target_properties(${PLUGIN_NAME} PROPERTIES
|
||||
CXX_VISIBILITY_PRESET hidden)
|
||||
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
|
||||
target_include_directories(${PLUGIN_NAME} INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef FLUTTER_PLUGIN_MY_PLUGIN_LINUX_PLUGIN_H_
|
||||
#define FLUTTER_PLUGIN_MY_PLUGIN_LINUX_PLUGIN_H_
|
||||
|
||||
#include <flutter_linux/flutter_linux.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#ifdef FLUTTER_PLUGIN_IMPL
|
||||
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define FLUTTER_PLUGIN_EXPORT
|
||||
#endif
|
||||
|
||||
G_DECLARE_FINAL_TYPE(Fl{{project_name.pascalCase()}}Plugin, fl_{{project_name.snakeCase()}}_plugin, FL,
|
||||
MY_PLUGIN_PLUGIN, GObject)
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT Fl{{project_name.pascalCase()}}Plugin* fl_{{project_name.snakeCase()}}_plugin_new(
|
||||
FlPluginRegistrar* registrar);
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void {{project_name.snakeCase()}}_plugin_register_with_registrar(
|
||||
FlPluginRegistrar* registrar);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif // FLUTTER_PLUGIN_MY_PLUGIN_LINUX_PLUGIN_H_
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "include/{{project_name.snakeCase()}}_linux/{{project_name.snakeCase()}}_plugin.h"
|
||||
|
||||
#include <flutter_linux/flutter_linux.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
const char kChannelName[] = "{{project_name.snakeCase()}}_linux";
|
||||
const char kGetPlatformName[] = "getPlatformName";
|
||||
|
||||
struct _Fl{{project_name.pascalCase()}}Plugin {
|
||||
GObject parent_instance;
|
||||
|
||||
FlPluginRegistrar* registrar;
|
||||
|
||||
// Connection to Flutter engine.
|
||||
FlMethodChannel* channel;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(Fl{{project_name.pascalCase()}}Plugin, fl_{{project_name.snakeCase()}}_plugin, g_object_get_type())
|
||||
|
||||
// Called when a method call is received from Flutter.
|
||||
static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
|
||||
gpointer user_data) {
|
||||
const gchar* method = fl_method_call_get_name(method_call);
|
||||
|
||||
g_autoptr(FlMethodResponse) response = nullptr;
|
||||
if (strcmp(method, kGetPlatformName) == 0)
|
||||
response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_string("Linux")));
|
||||
else
|
||||
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
|
||||
|
||||
g_autoptr(GError) error = nullptr;
|
||||
if (!fl_method_call_respond(method_call, response, &error))
|
||||
g_warning("Failed to send method call response: %s", error->message);
|
||||
}
|
||||
|
||||
static void fl_{{project_name.snakeCase()}}_plugin_dispose(GObject* object) {
|
||||
G_OBJECT_CLASS(fl_{{project_name.snakeCase()}}_plugin_parent_class)->dispose(object);
|
||||
}
|
||||
|
||||
static void fl_{{project_name.snakeCase()}}_plugin_class_init(Fl{{project_name.pascalCase()}}PluginClass* klass) {
|
||||
G_OBJECT_CLASS(klass)->dispose = fl_{{project_name.snakeCase()}}_plugin_dispose;
|
||||
}
|
||||
|
||||
Fl{{project_name.pascalCase()}}Plugin* fl_{{project_name.snakeCase()}}_plugin_new(FlPluginRegistrar* registrar) {
|
||||
Fl{{project_name.pascalCase()}}Plugin* self = FL_MY_PLUGIN_PLUGIN(
|
||||
g_object_new(fl_{{project_name.snakeCase()}}_plugin_get_type(), nullptr));
|
||||
|
||||
self->registrar = FL_PLUGIN_REGISTRAR(g_object_ref(registrar));
|
||||
|
||||
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
|
||||
self->channel =
|
||||
fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar),
|
||||
kChannelName, FL_METHOD_CODEC(codec));
|
||||
fl_method_channel_set_method_call_handler(self->channel, method_call_cb,
|
||||
g_object_ref(self), g_object_unref);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static void fl_{{project_name.snakeCase()}}_plugin_init(Fl{{project_name.pascalCase()}}Plugin* self) {}
|
||||
|
||||
void {{project_name.snakeCase()}}_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
|
||||
Fl{{project_name.pascalCase()}}Plugin* plugin = fl_{{project_name.snakeCase()}}_plugin_new(registrar);
|
||||
g_object_unref(plugin);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
name: {{project_name.snakeCase()}}_linux
|
||||
description: Linux implementation of the {{project_name.snakeCase()}} plugin
|
||||
version: 0.1.0+1
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ">=2.16.0 <3.0.0"
|
||||
flutter: ">=2.10.0"
|
||||
|
||||
flutter:
|
||||
plugin:
|
||||
implements: {{project_name.snakeCase()}}
|
||||
platforms:
|
||||
linux:
|
||||
pluginClass: {{project_name.pascalCase()}}Plugin
|
||||
dartPluginClass: {{project_name.pascalCase()}}Linux
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
{{project_name.snakeCase()}}_platform_interface:
|
||||
path: ../{{project_name.snakeCase()}}_platform_interface
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
very_good_analysis: ^2.4.0
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2022, Very Good Ventures
|
||||
// https://verygood.ventures
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:{{project_name.snakeCase()}}_linux/{{project_name.snakeCase()}}_linux.dart';
|
||||
import 'package:{{project_name.snakeCase()}}_platform_interface/{{project_name.snakeCase()}}_platform_interface.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('{{project_name.pascalCase()}}Linux', () {
|
||||
const kPlatformName = 'Linux';
|
||||
late {{project_name.pascalCase()}}Linux {{project_name.camelCase()}};
|
||||
late List<MethodCall> log;
|
||||
|
||||
setUp(() async {
|
||||
{{project_name.camelCase()}} = {{project_name.pascalCase()}}Linux();
|
||||
|
||||
log = <MethodCall>[];
|
||||
TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler({{project_name.camelCase()}}.methodChannel, (methodCall) async {
|
||||
log.add(methodCall);
|
||||
switch (methodCall.method) {
|
||||
case 'getPlatformName':
|
||||
return kPlatformName;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('can be registered', () {
|
||||
{{project_name.pascalCase()}}Linux.registerWith();
|
||||
expect({{project_name.pascalCase()}}Platform.instance, isA<{{project_name.pascalCase()}}Linux>());
|
||||
});
|
||||
|
||||
test('getPlatformName returns correct name', () async {
|
||||
final name = await {{project_name.camelCase()}}.getPlatformName();
|
||||
expect(
|
||||
log,
|
||||
<Matcher>[isMethodCall('getPlatformName', arguments: null)],
|
||||
);
|
||||
expect(name, equals(kPlatformName));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user