123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- //import 'package:oktoast/oktoast.dart';
- import 'dart:async';
- import 'dart:math';
- import 'package:flustars/flustars.dart' as FlutterStars;
- import 'package:flutter/material.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- import 'package:liftmanager/utils/fast_notification.dart';
- import 'package:liftmanager/utils/loading_dialog.dart';
- // import 'package:percent_indicator_example/sample_linear_page.dart';
- import 'package:percent_indicator/percent_indicator.dart';
- // import 'package:ftoast/ftoast.dart' as f;
- // import 'package:fsuper/fsuper.dart';
- /// Toast工具类
- //class Toast {
- // static show(String msg, {duration = 2000}) {
- // if (msg == null){
- // return;
- // }
- // showToast(
- // msg,
- // duration: Duration(milliseconds: duration),
- // dismissOtherToast: true
- // );
- // }
- //
- // static cancelToast() {
- // dismissAllToast();
- // }
- //}
- toastsF(context, String msg, {int timeInSecForIos}) {
- FToast().init(context);
- FToast().showToast(
- child: ClipRRect(
- borderRadius: BorderRadius.circular(50),
- child: Container(
- color: Color(0xffbbbbbb),
- padding: EdgeInsets.only(left: 15, right: 15, top: 8, bottom: 10),
- child: Text(
- msg,
- style: TextStyle(
- fontSize: 13,
- color: Color(0xffffffff),
- ),
- ),
- ),
- ),
- gravity: ToastGravity.BOTTOM,
- toastDuration: Duration(seconds: timeInSecForIos ?? 3),
- );
- }
- toasts(String msg, {int timeInSecForIos}) {
- Fluttertoast.showToast(
- msg: msg,
- backgroundColor: Color(0xffbbbbbb),
- textColor: Color(0xffffffff),
- fontSize: 13,
- toastLength: Toast.LENGTH_SHORT,
- gravity: ToastGravity.BOTTOM,
- timeInSecForIosWeb: timeInSecForIos);
- }
- showSnackBar(BuildContext context, String msg) {
- Scaffold.of(context).showSnackBar(SnackBar(content: Text('$msg')));
- }
- showLoading(BuildContext context, [String msg = '加载中...']) {
- showDialog<Null>(
- context: context, //BuildContext对象
- barrierDismissible: false,
- builder: (BuildContext context) {
- return LoadingDialog(
- //调用对话框
- text: msg,
- );
- });
- }
- showAlert(
- BuildContext context,
- String title,
- String content,
- String txt1,
- Function onPre1, {
- String txt2 = "",
- Function onPre2,
- String txt3 = "",
- Function onPre3,
- }) {
- showDialog(
- barrierDismissible: false,
- context: context,
- builder: (context) => new AlertDialog(
- title: new Text('${title}'),
- content: new Text('${content}'),
- actions: <Widget>[
- txt3.length > 0
- ? new FlatButton(
- onPressed: onPre3,
- child: new Text("${txt3}"),
- )
- : Container(),
- txt2.length > 0
- ? new FlatButton(
- onPressed: onPre2,
- child: new Text("${txt2}"),
- )
- : Container(),
- new FlatButton(
- onPressed: onPre1,
- child: new Text('${txt1}'),
- ),
- ],
- ),
- );
- }
- dismissLoading(BuildContext context) {
- Navigator.pop(context);
- }
- randomInt(int min, int max) {
- return new Random().nextInt(max) % (max - min + 1) + min;
- }
- showPercent(BuildContext context, Function fun, Function funBack) {
- double percent = 0.0;
- double width = MediaQuery.of(context).size.width;
- showDialog<Null>(
- context: context, //BuildContext对象
- barrierDismissible: false,
- builder: (BuildContext context) {
- return StatefulBuilder(builder: (context, state) {
- String textss = '上传中,请稍后~';
- Color col = Colors.white;
- FastNotification.addListener("percent", (obj) {
- print(obj);
- print("-----------/*/");
- print(FlutterStars.SpUtil.getString('uploadName'));
- // if(FlutterStars.SpUtil.getString('uploadName') == ""){
- // FlutterStars.SpUtil.putString('uploadName', obj["uploadName"]);
- // }
- if (obj["success"] == true) {
- state(() {
- percent = 1.0;
- textss = "上传成功!";
- print("这里是成功");
- // col = Colors.green;
- });
- // FastNotification.push("percent_back",percent);
- // funBack();
- new Future.delayed(Duration(milliseconds: 1000), () {
- funBack();
- });
- } else {
- state(() {
- textss = "上传失败!";
- col = Colors.red;
- });
- // fun();
- new Future.delayed(Duration(milliseconds: 1000), () {
- fun();
- });
- }
- print(
- "complate-----------------------------------------------------");
- });
- Timer _timer;
- const period = const Duration(seconds: 3);
- _timer = Timer.periodic(period, (timer) {
- if (percent >= 0.9) {
- _timer.cancel();
- } else {
- state(() {
- percent = double.parse((0.1 + percent).toStringAsFixed(2));
- print(percent);
- });
- }
- });
- return Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- child: new LinearPercentIndicator(
- alignment: MainAxisAlignment.center,
- width: 300,
- animation: false,
- animationDuration: 1000,
- lineHeight: 20.0,
- percent: percent,
- center: Text((percent * 100).toString() + '%',
- style:
- new TextStyle(fontSize: 12.0, color: Colors.white)),
- linearStrokeCap: LinearStrokeCap.roundAll,
- backgroundColor: Colors.grey,
- progressColor: Colors.blue,
- )),
- // Container(
- // padding: EdgeInsets.only(top:15),
- // child: Text(
- // textss,
- // style: new TextStyle(fontSize: 12.0,color:Colors.white,decoration: TextDecoration.none),
- // ),
- // ),
- ],
- ),
- );
- });
- });
- }
|