flutter_image_marker 0.0.5 flutter_image_marker: ^0.0.5 copied to clipboard
A image water maker Flutter plugin for android && ios.
example/lib/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_image_marker/flutter_image_marker.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
void main() {
runApp(const MyAppPrepare());
}
class MyAppPrepare extends StatelessWidget {
const MyAppPrepare({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: GestureDetector(
/// 全局键盘关闭
onTap: () {
FocusScopeNode focusScopeNode = FocusScope.of(context);
if (!focusScopeNode.hasPrimaryFocus && focusScopeNode.focusedChild != null) {
FocusManager.instance.primaryFocus?.unfocus();
}
},
child: const MyApp(),
),
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
GlobalWidgetsLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
locale: const Locale('zh'),
supportedLocales: const <Locale>[
Locale('zh'), // Chinese
// Locale('iw'), // Hebrew
],
);
}
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String imagePath = "";
String markerPath = "";
@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.
// We also handle the message potentially returning null.
try {
platformVersion = await FlutterImageMarker.platformVersion ?? 'Unknown platform version';
} 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('Plugin example app'),
),
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () async {
final List<AssetEntity>? result = await AssetPicker.pickAssets(context,
pickerConfig: const AssetPickerConfig(
maxAssets: 1,
requestType: RequestType.image,
));
if (result == null || result.isEmpty) {
return;
}
File? file = await result.first.originFile;
if (file != null) {
setState(() {
imagePath = file.path;
});
}
},
child: const Text(
"图片选择",
style: TextStyle(color: Colors.black, fontSize: 16),
)),
const SizedBox(
width: 16,
),
TextButton(
onPressed: () async {
try {
TengitsMakerModel mode = TengitsMakerModel();
mode.imagePath = imagePath;
mode.textColor = Colors.red;
mode.textBgColor = Colors.blue;
mode.text = "mark test";
mode.fontSize = 40;
mode.position = MarkerPosition.bottomLeft;
String? ret = await FlutterImageMarker.markText(mode);
if (ret == null) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('sdk调用返回为空'),
));
} else {
setState(() {
markerPath = ret;
});
}
} catch (exception) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('sdk调用异常了'),
));
}
},
child: const Text(
"打水印",
style: TextStyle(color: Colors.black, fontSize: 16),
)),
],
),
const SizedBox(
height: 16,
),
Row(
children: [
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: const Color(0xffEBEDF0),
border: Border.all(color: const Color(0xffE14C4C)),
borderRadius: BorderRadius.circular(4),
),
child: Offstage(
offstage: imagePath.isEmpty,
child: Image.file(
File(imagePath),
fit: BoxFit.fill,
),
),
),
Expanded(
child: Text(
"水印图片地址:" + markerPath,
style: const TextStyle(color: Colors.blue, fontSize: 16),
)),
],
),
if (markerPath.isNotEmpty)
Container(
width: 400,
height: 350,
decoration: BoxDecoration(
color: const Color(0xffEBEDF0),
border: Border.all(color: const Color(0xffE14C4C)),
borderRadius: BorderRadius.circular(4),
),
child: Image.file(
File(markerPath),
fit: BoxFit.fill,
),
),
],
)),
);
}
}