progress.dart 2.18 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';

import '../../utils/screen_util.dart';

class Progress extends StatelessWidget {
  final double value;
  final double size;
  Progress(this.value, {this.size = 100.0});

  Widget get progress {
    return Container(
      width: ScreenUtil().setWidth(30),
      height: ScreenUtil().setWidth(30),
      padding: EdgeInsets.all(10),
      // color: Colors.red,
      child: CircularProgressIndicator(
        value: value,
        // strokeWidth: 14,
        backgroundColor: Colors.grey[200],
      ),
    );
  }

  Widget get progressText {
    final integer = (value * 100).toInt(); //当前上传进度
    final decimal = (((value * 100) - integer) * 100).toInt(); //剩余进度
    final unit = '%';

    return DefaultTextStyle(
        style: TextStyle(
          color: Colors.black87,
          // fontWeight: FontWeight.bold,
        ),
        child:
            // Row(
            //   mainAxisSize: MainAxisSize.min,
            //   children: [
            // Text(
            //   integer.toString(),
            //   style: TextStyle(fontSize: ScreenUtil().setSp(13)),
            // ),
            // Column(
            //   children: [
            Container(
                width: ScreenUtil().setWidth(size * 2),
                height: ScreenUtil().setWidth(size * 2),
                decoration: BoxDecoration(
                    color: Color.fromRGBO(0, 0, 0, 0.5),
                    borderRadius: BorderRadius.circular(r(5))),
                child: Center(
                  child: Text('${integer}${unit}',
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(24),
                          color: MyColours.color_fefefe)),
                ))

        // Text('.$decimal',
        //     style: TextStyle(fontSize: ScreenUtil().setSp(13))),
        //     ],
        //   )
        // ],
        );
  }

  @override
  Widget build(BuildContext context) {
    // return Stack(
    //   alignment: AlignmentDirectional.center,
    //   children: [progress, progressText],
    // );
    return progressText;
  }
}