nos 1.0.0-rc.0 copy "nos: ^1.0.0-rc.0" to clipboard
nos: ^1.0.0-rc.0 copied to clipboard

NOS_CORE.

example/lib/main.dart

/*
 *  Copyright (c) 2021 NetEase, Inc.  All rights reserved.
 *  Use of this source code is governed by a MIT license that can be found in the LICENSE file
 */

import 'package:flutter/material.dart';
import 'dart:async';

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _appKey = '';//your appKey

  @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.
    try {} 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;
    });
  }

  /// example upload file
  Future<int> uploadFile( String zipPath) {
    var completer = Completer<int>();
    var sdkType = 'nos-flutter';
    NosPlugin().uploadSync(sdkType, "nos-flutter-1.0.0", zipPath, _appKey, (code, data) {
      if (data.state == UploadState.uploadOK) {
        completer.complete(0);
      } else if (data.state != UploadState.uploading) {
        if(!completer.isCompleted){
          completer.complete(UploadState.uploadFail.index);
        }
      }
    });
    return completer.future;
  }

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