jlcool / aliossflutter

阿里云oss flutter
Apache License 2.0
76 stars 47 forks source link

无法初始化 #38

Closed Cocomart closed 3 years ago

Cocomart commented 3 years ago

我引入包之后,调用init或者secretInit。控制台返回提示,未找到这两个方法的实现。 MissingPluginException(No implementation found for method secretInit on channel aliossflutter) 下面是我的代码

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

import './page/root/dynamic.dart';
import './page/root/shop.dart';
import './page/root/center.dart';

import 'package:flutter/services.dart';

import 'package:flutter_app/components/toats.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  PageController _controller;
  int page = 0;
  static DateTime _startedTime;

  final String accessKeyId = "LTAI0pnKdX7I5Rk1";
  final String accessKeySecret = "AkYIfYsvjpaBYzqL86f7xv8yNOfc1X";
  final String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";

  AliOSSFlutter alioss = AliOSSFlutter();

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    _controller = new PageController(initialPage: this.page, keepPage: true);
    Timer(Duration(milliseconds: 1000),
        () => {alioss.secretInit(accessKeyId, accessKeySecret, endpoint)});

    alioss.responseFromInit.listen((data) {
      print(data);
    });
  }

  void onTap(int index) {
    setState(() {
      this.page = index;
      _controller.jumpToPage(page);
    });
  }

  void _onPageChanged(int page) {
    setState(() {
      this.page = page;
    });
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);

    return WillPopScope(
      onWillPop: listenerKeyBack,
      child: Scaffold(
          body: new PageView(
            physics: NeverScrollableScrollPhysics(),
            controller: _controller,
            onPageChanged: _onPageChanged,
            children: <Widget>[new Dynamic(), new Shop(), new CenterMy()],
          ),
          bottomNavigationBar: Container(
              height: ScreenUtil().setWidth(90),
              width: ScreenUtil().setWidth(750),
              color: Colors.black,
              child: new BottomNavigationBar(
                  selectedFontSize: ScreenUtil().setWidth(0),
                  unselectedFontSize: ScreenUtil().setWidth(0),
                  iconSize: ScreenUtil().setWidth(50),
                  backgroundColor: Color(0xffF3F3F3),
                  items: [
                    new BottomNavigationBarItem(
                        icon: Icon(Icons.home), title: Text('')),
                    new BottomNavigationBarItem(
                        icon: Icon(Icons.shopping_cart), title: Text('')),
                    new BottomNavigationBarItem(
                        icon: Icon(Icons.people), title: Text(''))
                  ],
                  currentIndex: page,
                  onTap: onTap))),
    );
  }

  // 监听返回键
  Future<bool> listenerKeyBack() async {
    if (_startedTime == null) {
      _startedTime = new DateTime.now();
      Toast.toast(context, '再次点击退出');
    } else {
      SystemChannels.platform.invokeMethod('SystemNavigator.pop');
    }
    // 等待两秒
    await Future.delayed(Duration(milliseconds: 2000));

    // 2秒后移除toast
    if (DateTime.now().difference(_startedTime).inMilliseconds >= 2000) {
      _startedTime = null;
    }
    return Future.value(false);
  }
}