import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';

class CalibrationProgressWidget extends StatelessWidget {
  final ValueNotifier<double> progressNotifier;
  final ValueNotifier<bool> failureNotifier;

  const CalibrationProgressWidget({
    Key? key,
    required this.progressNotifier,
    required this.failureNotifier,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<double>(
      valueListenable: progressNotifier,
      builder: (context, progress, _) {
        return ValueListenableBuilder<bool>(
          valueListenable: failureNotifier,
          builder: (context, isFailure, __) {
            return Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Text(
                  isFailure ? '失败'.tr : '${progress.toStringAsFixed(0)}%',
                  style: TextStyle(
                    fontSize: 26.rpx,
                    color: isFailure
                        ? Colors.red
                        : themeController.currentColor.sc3,
                  ),
                ),
                SizedBox(height: 40.rpx),
                Stack(
                  children: [
                    Container(
                      width: double.infinity,
                      height: 21.rpx,
                      decoration: BoxDecoration(
                        color: stringToColor("#D9D9D9"),
                        borderRadius: BorderRadius.circular(
                          AppConstants().button_container_radius,
                        ),
                      ),
                    ),
                    Container(
                      width: progress / 100 *
                          MediaQuery.of(context).size.width *
                          0.8,
                      height: 21.rpx,
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          colors: isFailure
                              ? [themeController.currentColor.sc9]
                              : [
                                  themeController.currentColor.sc2,
                                  themeController.currentColor.sc2,
                                ],
                          begin: Alignment.centerLeft,
                          end: Alignment.centerRight,
                        ),
                        borderRadius: BorderRadius.circular(
                          AppConstants().button_container_radius,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            );
          },
        );
      },
    );
  }
}
