Reputation: 4493
This my first time in how to create a plugin for my flutter project. I have simple *.dart file that has an only one method. My flutter app sends the ling and query parameters and the method goes and gets the data from internet.
Due to some security issue I need to create a plugin so my flutter mobile app can consume the data using the plugin.
My simple *.dart file uses 2 plugin as; http and tripledes.
In youtube one of the example shows how to create plugin but also edits some file under android and iOS folder. In my scenario I don't want to use any platform specific futures. This made me more confuse how to create one.
Based on my simple *.dart file that shows on below, how can I create a plugin to use in flutter mobile app project?
import 'dart:io';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http; // Uses http: ^0.12.0+1 plugin
import '/nick_security/nickDecrypt.dart'; // I have a some dart file that Uses tripledes: ^2.1.0 plugin
import '/nick_security/nickEncrypt.dart'; // I have a some dart file that Uses tripledes: ^2.1.0 plugin
Future<List<List<dynamic>>> getQueryFromSocket(String _qLink, String _qParameter) async {
List<List<dynamic>> _returnData;
String _QueryLink = _qLink;
String _QueryParameters = _qParameter;
Sting _dbSocketConnectionString = _QueryLink + “/“ + _QueryParameters;
var _response = await http.get(Uri.encodeFull("$_dbSocketConnectionString"),
headers: {'Accept': 'application/json'});
if (_response.statusCode == 200) {
var _resBody = await json.decode(_response.body);
// Decrypt data first using nickDecrypt(_resBody); and then
// Do some computing and add result into —> List<List<dynamic>> _returnData
return _returnData;
} else {
// Create single item for list to say there is a error
// and add result into —> List<List<dynamic>> _returnData
return _returnData;
}
}
Upvotes: 0
Views: 531
Reputation: 10660
Flutter plugins are meant to be able to add platform-specific code.
You want to create a Flutter package. A Flutter package contains only Dart-code. Here are some of the steps you need to do to create a flutter package. https://medium.com/nonstopio/create-flutter-package-and-publish-to-dart-packages-timer-button-8a407440a5da
Upvotes: 1