education 0.0.4 copy "education: ^0.0.4" to clipboard
education: ^0.0.4 copied to clipboard

discontinued
outdated

android api

example/lib/main.dart

import 'dart:io';

import 'package:education_example/my_crop_image.dart';
import 'package:education_example/second_screen.dart';
import 'package:education_example/three.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:education/education.dart';

//import 'package:path_provider/path_provider.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized(); // 确保应用程序已经初始化完成
  //await cleanUpExpiredFiles();

  runApp(
    MaterialApp(
      //home: MyApp(),
      home: MyCropImage(),
    ),
  );
}

// 删除指定目录下所有超过过期时间的图片文件
/*void cleanUpExpiredFiles() async {
  final appDocumentsDirectory = await getApplicationDocumentsDirectory();
  final directory = Directory(appDocumentsDirectory.path);

  final files = directory.listSync(); // 获取目录下的所有文件

  final currentTime = DateTime.now();
  final expiryDuration = Duration(days: 7); // 设置过期时间为7天

  for (var file in files) {
    if (file is File) {
      final fileStat = await file.stat();
      final lastModified = fileStat.modified;

      if (currentTime.difference(lastModified) >= expiryDuration) {
        file.deleteSync(); // 删除过期文件
      }
    }
  }
}*/

/*
//java 代码
 public static void cleanUpExpiredFiles(Context context) {
        File appDocumentsDir = context.getFilesDir();
        File[] files = appDocumentsDir.listFiles();

        if (files != null) {
            long currentTime = System.currentTimeMillis();
            long expiryDuration = 7 * 24 * 60 * 60 * 1000; // 设置过期时间为7天

            for (File file : files) {
                long lastModified = file.lastModified();

                if (currentTime - lastModified >= expiryDuration) {
                    file.delete(); // 删除过期文件
                }
            }
        }
    }
*/

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  static const _channel = MethodChannel('my.example.com/native');
  static const _platform = MethodChannel('toFlutterChannelName');

  String _sourceImage = 'Unknown';
  String _cropImage = 'Unknown';

  String imagePath = "";
  final _educationPlugin = Education();

  List<List> _imageArray = [];

  //字符串转二维List
  List<List> _returnListTwo(s) {
    List<List> rlt = [];
    List zz;
    //字符串变二维列表
    s = s.replaceAll("[", "");
    s = s.replaceAll("]", "");

    zz = s.split(",");
    //print("zzzzzzzzzzz");
    //print(zz);

    var x = 0;
    for (int i = 0; i < zz.length / 4; i++) {
      List l = [];
      l.add(zz[x]);
      l.add(zz[x + 1]);
      l.add(zz[x + 2]);
      l.add(zz[x + 3]);
      //print("llllllllllllllllll");
      //print(l);

      rlt.add(l);

      x = x + 4;
    }

    //print("rlt");
    //print(rlt);
    //print(rlt[0]);
    //print(rlt[0][0]);
    return rlt;
  }

  //测试
  Future<void> test() async {
    try {
      imagePath = (await _educationPlugin.getGalleryImage())!;
      print(imagePath);

      //setState(() {});
    } on PlatformException catch (e) {
      // 处理原生端返回的错误
      print('Error: ${e.message}');
    }
  }

  @override
  void initState() {
    super.initState();
    //_platform.setMethodCallHandler(flutterMethod);

    //getGalleryImage();
    //showWhenLocked();
  }

  //此处是核心代码,覆写生命周期函数 onNewIntent 接收到广播时,调用 flutter 跳转页面
  /*
  @Override
  public boolean onNewIntent(Intent intent) {
    boolean res = sendNotificationPayloadMessage(intent);
    if (res && mainActivity != null) {
      mainActivity.setIntent(intent);
    }
    return res;
  }
  */

  void onDidReceiveNotificationResponse() async {
    await Navigator.push(
      context,
      MaterialPageRoute<void>(builder: (context) => SecondScreen()),
    );
  }

  Future<dynamic> flutterMethod(MethodCall methodCall) async {
    switch (methodCall.method) {
      case 'flutterMethod':
        debugPrint('Android调用了flutterMethod方法!!!');
        debugPrint('Android传递给flutter的参数是:' + methodCall.arguments);
        onDidReceiveNotificationResponse();
        break;
      default:
        debugPrint('Android调用了flutterMethod失败!!!\t\t' + methodCall.method);
    }
  }

  // 定义调用原生方法的方法
  Future<void> callNativeFunction() async {
    try {
      final result = await _channel.invokeMethod('nativeFunction');
      print(result);
    } on PlatformException catch (e) {
      print("Error calling native function: ${e.message}");
      throw e;
    }
  }

  Future<void> getSourceImage() async {
    try {
      String? result = await _educationPlugin.getGalleryImage();
      _imageArray = _returnListTwo(result);

      print("返回的图片二维数组--------------------------------");
      print(_imageArray);

      setState(() {});
    } on PlatformException catch (e) {
      print(e.message);
    }
  }

  Future<void> getCropImage() async {
    try {
      _cropImage = (await _educationPlugin.getCropImage({
        "path": "/storage/emulated/0/DCIM/.thumbnails/1680692964164.jpg",
        "key": "key"
      }))!;

      setState(() {});
    } on PlatformException catch (e) {
      // 处理原生端返回的错误
      print('Error: ${e.message}');
    }
  }

  Future<void> showWhenLocked() async {
    try {
      String result = (await _educationPlugin.showWhenLocked())!;
      print(result);
    } on PlatformException catch (e) {
      // 处理原生端返回的错误
      print('Error: ${e.message}');
    }
  }

  Future<void> hiddenWhenLocked() async {
    try {
      String result = (await _educationPlugin.hiddenWhenLocked())!;
      print(result);
    } on PlatformException catch (e) {
      // 处理原生端返回的错误
      print('Error: ${e.message}');
    }
  }

  Future<void> setClock() async {
    try {
      String result = (await _educationPlugin.setClock())!;
      print(result);
    } on PlatformException catch (e) {
      // 处理原生端返回的错误
      print('Error: ${e.message}');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }

  Widget _returnBody() {
    return Container(
      child: Column(
        children: [
          Expanded(
            child: imagePath != ""
                ? Container(
                    child: Image.file(File(imagePath)),
                  )
                : Container(),
          ),

          GestureDetector(
            onTap: () async {
              test();
            },
            child: Container(
              width: 200,
              height: 200,
              color: Colors.green,
            ),
          ),

          //相册图片展示
          /*Container(
              color: Colors.green,
              height: 300,
              child: GridView.count(
                mainAxisSpacing: 4.0,
                crossAxisSpacing: 6.0,
                padding: EdgeInsets.only(
                  left: 8,
                  right: 8,
                ),
                crossAxisCount: 2,
                childAspectRatio: 1.5,
                children: _returnImage(),
              ),
            ),*/
        ],
      ),
    );
  }

  List<Widget> _returnImage() {
    List<Widget> imageList = [];

    for (int i = 0; i < _imageArray.length; i++) {
      imageList.add(
        Container(
          color: Colors.orange,
          child: Image.file(
            File(
              _imageArray[i][1].trim(),
              //"/storage/emulated/0/DCIM/Screenshots/Screenshot_2023-04-04-14-38-37-995_net.csdn.csdnplus.jpg",
            ),
            fit: BoxFit.cover,
          ),
        ),
      );
    }

    return imageList;
  }
}
0
likes
0
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

android api

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on education

Packages that implement education