vone_ipfs 0.0.30 copy "vone_ipfs: ^0.0.30" to clipboard
vone_ipfs: ^0.0.30 copied to clipboard

A IPFS project.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:vone_ipfs/bean/upload_result_entity.dart';

import 'package:vone_ipfs/component/file_upload_view.dart';
import 'package:vone_ipfs/utils/ipfs_utils.dart';
import 'package:vone_ipfs/component/image_upload_view.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: HomePage(),
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final List<UploadResultEntity> _files = [];

  bool isAllowCloud = true;
  bool isFixedDir = true;
  int maxCount = 5;

  @override
  void initState() {
    super.initState();
    IPFSUtils.getInstance('29634358-bbca-4a69-9336-95917796e2c4');
    IPFSUtils.instance!.initUserId("root");
    // Future.delayed(Duration(seconds: 10),(){
    //   setState(() {
    //     _files.add(UploadResultEntity(IPFSUtils.instance!.getFilePath('81', 'aaaa.jpg'),'','aaaa.jpg'));
    //   });
    // });
    // Future.delayed(Duration(seconds: 20),(){
    //   setState(() {
    //     _files.add(UploadResultEntity(IPFSUtils.instance!.getFilePath('81', 'aaaa.jpg'),'','aaaa.jpg'));
    //     _files.add(UploadResultEntity(IPFSUtils.instance!.getFilePath('81', 'aaaa.jpg'),'','aaaa.jpg'));
    //   });
    // });

  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [

        Padding(
          padding: EdgeInsets.symmetric(vertical: 10),
          child: Text(
            '配置',
            style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
          ),
        ),
        Row(children: [
          Text('云端'),
          Switch(value: isAllowCloud, onChanged: (value){
            setState(() {
              isAllowCloud = !isAllowCloud;
            });
          }),
          Text('固定目录'),
          Switch(value: isFixedDir, onChanged: (value){
            setState(() {
              isFixedDir = !isFixedDir;
            });
          }),
        ],),
        Padding(
          padding: EdgeInsets.symmetric(vertical: 10),
          child: Text(
            '文件上传',
            style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
          ),
        ),
        Container(
          child: FileUploadView(
            _files,
            '503',
            'vonevone',
            (files) {
              print(files);
            },
            maxCount: maxCount,
            isCanEdit: true,
            fileType: IPFSFileType.any,
            // allowedExtensions: ['jpg', 'png', 'doc', 'docx', 'ppt'],
            isFixedDir: isFixedDir,
            isAllowCloud: isAllowCloud,
          ),
          padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
        ),
        Padding(
          padding: EdgeInsets.symmetric(vertical: 10),
          child: Text('单图片上传',
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
        ),
        ImageUploadView(
          images: [UploadResultEntity('', '', 'fileName',0)],
          dirName: 'vonevone',
          dirId: '503',
          isFixedDir: isFixedDir,
          placeholder: 'images/ic_pdf.png',
          isAllowCloud: isAllowCloud,
          isCanEdit: true,
          fileType: IPFSFileType.imageAndVideo,
          uploadMode: UploadMode.SINGLE,
          btnPosition: UploadBtnPosition.RIGHT,
          valueChangedCallback: (value) {
            print(value);
          },
        ),
        Padding(
          padding: EdgeInsets.symmetric(vertical: 10),
          child: Text('多图片上传,指定顶部空间',
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
        ),
        ImageUploadView(
          dirName: 'vonevone',
          dirId: '503',
          images: [],
          isCanEdit: true,
          isFixedDir: isFixedDir,
          isAllowCloud: isAllowCloud,
          uploadMode: UploadMode.MULTIPLE,
          fileType: IPFSFileType.imageAndVideo,
          maxCount: maxCount,
          btnPosition: UploadBtnPosition.TOP,
          addImageWidget: Container(
            child: Text(
              '上传',
              style: TextStyle(fontSize: 16, color: Colors.white),
            ),
            width: 200,
            height: 50,
            color: Colors.blue,
            alignment: Alignment.center,
          ),
          valueChangedCallback: (value) {
            print(value);
          },
        ),
        Padding(
          padding: EdgeInsets.symmetric(vertical: 10),
          child: Text('多图片上传',
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
        ),
        ImageUploadView(
          dirName: 'vonevone',
          dirId: '503',
          images: [],
          isCanEdit: true,
          maxCount: maxCount,
          isFixedDir: isFixedDir,
          isAllowCloud: isAllowCloud,
          uploadMode: UploadMode.MULTIPLE,
          valueChangedCallback: (value) {
            print(value);
          },
        ),
      ],
    );
    // return Center(
    //   child: InkWell(
    //     child: Text('Running on:'),
    //     onTap: () {
    //       IPFSUtils.fileUploadSingle(context, (value) {});
    //     },
    //   ),
    // );
  }
}