import 'package:alert_banner/exports.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:oc_front/widgets/dialog/alert.dart'; // ignore: must_be_immutable class SubTextInputWidget extends StatefulWidget { String subkey; String? initialValue; double width; bool empty; bool noLabel; bool readOnly = false; bool copyLabel = false; void Function(String) change = (value) {}; SubTextInputWidget ({ super.key, required this.subkey, this.readOnly = false, this.noLabel = false, this.copyLabel = false, this.initialValue, required this.width, required this.empty, required this.change }); @override SubTextInputWidgetState createState() => SubTextInputWidgetState(); } class SubTextInputWidgetState extends State { @override Widget build(BuildContext context) { if (widget.readOnly && widget.initialValue == null) { return Container(); } TextEditingController ctrl = TextEditingController(text: widget.initialValue); return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Tooltip( message: widget.subkey, child: Container( margin: EdgeInsets.only(top: widget.empty ? 0 : 15), width: widget.width - (widget.readOnly ? 40 : 0), height: 30, child: TextFormField( textAlign: TextAlign.start, enabled: !widget.readOnly, controller: ctrl, onChanged: widget.change, style: const TextStyle(fontSize: 12), decoration: InputDecoration( hintText: "enter ${widget.subkey}...", fillColor: Colors.white, filled: true, labelText: widget.noLabel ? "" : widget.subkey, alignLabelWithHint: false, errorStyle: const TextStyle(fontSize: 0), hintStyle: const TextStyle(fontSize: 10), labelStyle: const TextStyle(fontSize: 12), floatingLabelBehavior: FloatingLabelBehavior.always, enabledBorder: const OutlineInputBorder(borderSide: BorderSide(color: Colors.grey)), border: const OutlineInputBorder(borderSide: BorderSide(color: Colors.grey)), contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), ), ))), widget.readOnly ? InkWell( onTap: () { Clipboard.setData(ClipboardData(text: widget.copyLabel ? "\$${widget.subkey}" : widget.initialValue!)); showAlertBanner(context, () {}, const InfoAlertBannerChild(text: "successfully add to clipboard"), // <-- Put any widget here you want! alertBannerLocation: AlertBannerLocation.bottom,); }, child: Container( margin: EdgeInsets.only(left: 5, top: widget.empty ? 0 : 15), decoration: BoxDecoration(borderRadius: BorderRadius.circular(5), border: Border.all(color: Colors.grey, width: 1)), width: 35, height: 30, child: const Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.copy, color: Colors.black, size: 15,) ]), )) : Container() ]); } }