61 lines
3.1 KiB
Dart
61 lines
3.1 KiB
Dart
import 'package:alert_banner/exports.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:oc_front/widgets/dialog/alert.dart';
|
|
|
|
class SubTextInputWidget extends StatefulWidget {
|
|
String subkey;
|
|
String? initialValue;
|
|
double width;
|
|
bool empty;
|
|
bool noLabel;
|
|
bool readOnly = false;
|
|
void Function(String) change = (value) {};
|
|
SubTextInputWidget ({ Key? key,
|
|
required this.subkey, this.readOnly = false, this.noLabel = false,
|
|
this.initialValue, required this.width, required this.empty, required this.change }):
|
|
super(key: key);
|
|
@override SubTextInputWidgetState createState() => SubTextInputWidgetState();
|
|
}
|
|
class SubTextInputWidgetState extends State<SubTextInputWidget> {
|
|
|
|
@override Widget build(BuildContext context) {
|
|
if (widget.readOnly && widget.initialValue == null) {
|
|
return Container();
|
|
}
|
|
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,
|
|
initialValue: widget.initialValue,
|
|
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.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()
|
|
]);
|
|
}
|
|
} |