123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import 'package:flutter/material.dart';
- /// annot_attribute_options_widget.dart
- ///
- /// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
- ///
- /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- /// This notice may not be removed from this file.
- typedef AnnotSliderValueOptionsCallback = void Function(double value);
- enum ValueShowType { sourceValue, percentage }
- class BaseSliderWidget extends StatefulWidget {
- final double sliderCurrentValue;
- final double sliderMaxValue;
- final double sliderMinValue;
- final IconData icon;
- final ValueShowType valueShowType;
- final String valueText;
- final AnnotSliderValueOptionsCallback sliderValueCallback;
- const BaseSliderWidget(
- {Key? key,
- required this.sliderCurrentValue,
- required this.sliderMinValue,
- required this.sliderMaxValue,
- required this.icon,
- this.valueText = "",
- this.valueShowType = ValueShowType.percentage,
- required this.sliderValueCallback})
- : super(key: key);
- @override
- State<BaseSliderWidget> createState() => _BaseSliderWidgetState();
- }
- class _BaseSliderWidgetState extends State<BaseSliderWidget> {
- late double currentSliderValue = 0.0;
- @override
- void initState() {
- super.initState();
- currentSliderValue = widget.sliderCurrentValue.toDouble();
- }
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 8),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Icon(widget.icon),
- Expanded(
- child: Slider(
- min: widget.sliderMinValue,
- max: widget.sliderMaxValue,
- value: currentSliderValue,
- onChanged: (data) {
- setState(() {
- currentSliderValue = data;
- widget.sliderValueCallback(currentSliderValue.roundToDouble());
- });
- }
- )),
- if(widget.valueText.isEmpty) ...[
- Container(
- width: 50,
- child: Text(widget.valueShowType == ValueShowType.percentage
- ? '${((currentSliderValue / widget.sliderMaxValue) * 100).round()}%'
- : currentSliderValue.round().toString()),
- )
- ]else ...[
- Container(
- width: 50,
- child: Text(widget.valueText),
- )
- ]
- ],
- ));
- }
- }
- Widget colorAlphaWidget({int currentAlphaValue = 0, double sliderMaxValue = 255, required AnnotSliderValueOptionsCallback alphaOptionsCallback}){
- return BaseSliderWidget(sliderCurrentValue: currentAlphaValue.toDouble(),sliderMinValue: 0, sliderMaxValue: sliderMaxValue, icon: Icons.invert_colors, sliderValueCallback: alphaOptionsCallback);
- }
|