Skip to content

Instantly share code, notes, and snippets.

@Zujaj
Created May 19, 2022 10:48
Show Gist options
  • Save Zujaj/2a7b3edcfed79b1d5e3759c008f653b1 to your computer and use it in GitHub Desktop.
Save Zujaj/2a7b3edcfed79b1d5e3759c008f653b1 to your computer and use it in GitHub Desktop.
The ColorTextField Widget.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:svg_colorization/utils/util.dart';
/// A [CupertinoTextField] widget that copies the selected or typed color.
class ColorTextField extends StatelessWidget {
const ColorTextField({
Key? key,
required this.colorTextController,
}) : super(key: key);
final TextEditingController colorTextController;
@override
Widget build(BuildContext context) {
return CupertinoTextField(
controller: colorTextController,
prefix: const Padding(
padding: EdgeInsets.only(left: 8), child: Icon(Icons.tag)),
suffix: IconButton(
icon: const Icon(Icons.content_paste_rounded),
onPressed: () async => Util.copyToClipboard(colorTextController.text),
),
autofocus: true,
maxLength: 9,
inputFormatters: [
// Any custom input formatter can be passed
// here or use any Form validator you want.
UpperCaseTextFormatter(),
FilteringTextInputFormatter.allow(RegExp(kValidHexPattern)),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment