123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- import 'package:flutter/material.dart';
- import 'package:kmpdfkit_demo/widgets/constains.dart';
- import 'package:kmpdfkit_demo/widgets/models/annot_attribute_bean.dart';
- import 'attr_color_list_widget.dart';
- import 'base_slider_widget.dart';
- typedef AttrFreeTextCallback = Function(AnnotAttributeBean);
- /// attr_free_text_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.
- class AttrFreeTextWidget extends StatefulWidget {
- AnnotAttributeBean bean;
- AttrFreeTextCallback callback;
- AttrFreeTextWidget({Key? key, required this.bean, required this.callback})
- : super(key: key);
- @override
- State<AttrFreeTextWidget> createState() => _AttrFreeTextWidgetState();
- }
- class _AttrFreeTextWidgetState extends State<AttrFreeTextWidget> {
- bool _isFontWidget = true;
- bool isBold = false;
- @override
- Widget build(BuildContext context) {
- return Column(
- children: [
- Row(
- children: [
- Expanded(
- child: TextButton(
- onPressed: () {
- setState(() {
- _isFontWidget = true;
- });
- },
- child: Text(
- 'FONT',
- style: TextStyle(
- color: _isFontWidget ? Colors.blue : Colors.grey,
- fontWeight: _isFontWidget
- ? FontWeight.bold
- : FontWeight.normal),
- ))),
- Expanded(
- child: TextButton(
- onPressed: () {
- setState(() {
- _isFontWidget = false;
- });
- },
- child: Text('STYLE',
- style: TextStyle(
- color: !_isFontWidget ? Colors.blue : Colors.grey,
- fontWeight: !_isFontWidget
- ? FontWeight.bold
- : FontWeight.normal))))
- ],
- ),
- _isFontWidget ? _fontWidget() : _styleWidget()
- ],
- );
- }
- Widget _fontWidget() {
- return Column(
- key: const ValueKey('free_text_font'),
- children: [
- Row(
- children: [
- TextButton(
- onPressed: () {
- setState(() {
- widget.bean.fontBold = !widget.bean.fontBold;
- widget.callback(widget.bean);
- });
- },
- child: Text('B',
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 16,
- color:
- widget.bean.fontBold ? Colors.blue : Colors.grey))),
- TextButton(
- onPressed: () {
- setState(() {
- widget.bean.fontItalic = !widget.bean.fontItalic;
- widget.callback(widget.bean);
- });
- },
- child: Text('I',
- style: TextStyle(
- fontWeight: FontWeight.bold,
- fontSize: 16,
- fontStyle: FontStyle.italic,
- color: widget.bean.fontItalic
- ? Colors.blue
- : Colors.grey)))
- ],
- ),
- ListView(
- primary: true,
- shrinkWrap: true,
- children: [
- for (var value in FontType.values) ...{
- ListTile(
- title: Text(value.name),
- trailing: widget.bean.fontType == value
- ? const Icon(Icons.check)
- : null,
- onTap: () {
- setState(() {
- widget.bean.fontType = value;
- widget.callback(widget.bean);
- });
- },
- ),
- const Divider(color: Colors.grey, height: 1)
- }
- ],
- )
- ],
- );
- }
- Widget _styleWidget() {
- return Column(
- key: const ValueKey('free_text_style'),
- children: [
- ColorListWidget(
- color: widget.bean.textColor,
- colorOptionsCallback: (textColor) {
- widget.bean.textColor = textColor;
- widget.callback(widget.bean);
- }),
- colorAlphaWidget(
- currentAlphaValue: widget.bean.textColorAlpha,
- alphaOptionsCallback: (textColorAlpha) {
- widget.bean.textColorAlpha = textColorAlpha.round();
- widget.callback(widget.bean);
- }),
- BaseSliderWidget(
- sliderCurrentValue: widget.bean.fontSize.toDouble(),
- sliderMinValue: 1,
- sliderMaxValue: 100,
- icon: Icons.format_size,
- valueShowType: ValueShowType.sourceValue,
- sliderValueCallback: (fontSize) {
- widget.bean.fontSize = fontSize.round();
- widget.callback(widget.bean);
- })
- ],
- );
- }
- }
|