reshub_flutter 0.0.15
reshub_flutter: ^0.0.15 copied to clipboard
Flutter版本的shiply资源sdk
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:reshub_flutter/reshub_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ReshubFlutter reshubInstance = ReshubFlutter();
StringBuffer textLog = StringBuffer();
String _platformVersion = 'Unknown';
String resId = "test_hippy_search_android";
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// reshubInstance = ReshubFlutter();
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await ReshubFlutter.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
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('reshub flutter plugin example app'),
),
body: Column(children: [
ElevatedButton(onPressed: _onPressInit, child: const Text('init ')),
ElevatedButton(onPressed: _onPressGet, child: const Text('call get ')),
ElevatedButton(onPressed: _onPressGetLatest, child: const Text('call getLatest ')),
ElevatedButton(onPressed: _onPressLoad, child: const Text('call load ')),
ElevatedButton(onPressed: _onPressLoadLatest, child: const Text('call loadLatest ')),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Text(textLog.toString()),
))
]),
),
);
}
void _onPressInit() {
Map<String, String> params = Map();
params["testKey"] = "testValue";
ReshubFlutter.initReshubCenter("device123", "1.2.3", true, params);
// https://shiply.tds.woa.com/project/setting/normal?projectId=195 shiply体验项目 RDeliveryDemo-Android 产品
if (Platform.isIOS) {
resId = "testpatch";
ReshubFlutter.initReshub("14e1a90fcd", "d96d3d4a-fe58-4b8d-99c4-61d894a3d3bb", "online");
printText('init called, platform = iOS');
} else if(Platform.isAndroid) {
ReshubFlutter.initReshub("9d256c9ecc", "bfe91841-af1a-4572-9868-8b3c70a8d19c", "online");
printText('init called, platform = Android');
}
}
void _onPressGet() {
reshubInstance.get(resId).then(
(value) => printText("get result => path: ${value?.localPath} "));
}
void _onPressGetLatest() {
reshubInstance.getLatest(resId).then(
(value) => printText("getLatest result => path: ${value?.localPath} "));
}
void _onPressLoad() {
reshubInstance.load(resId).then(
(value) => printText("load result => isSuccess: ${value.isSuccess} "
"path: ${value.resModel?.localPath},originLocalPath: ${value.resModel?.originLocalPath}"));
}
void _onPressLoadLatest() {
reshubInstance.loadLatest(resId).then(
(value) => printText("loadLatest result => isSuccess: ${value.isSuccess} path: ${value.resModel?.localPath}"));
}
void printText(String log) {
textLog.write('$log\n');
setState(() {
});
}
}