Reputation: 1022
I added initial value like this, But user can edit initial text. How to disable to edit initial value? But user can be able to add value with initial value?
var _myController = TextEditingController(text: "https://");
Output should be like this
print(url);
Upvotes: 0
Views: 263
Reputation: 268114
You can try this logic, this way https://
will always be shown to the user, if user enters a url without https://
we are good, and if a user enters url with https://
we are again good.
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: _controller,
decoration: InputDecoration(prefixText: "https://"),
),
RaisedButton(
child: Text("Submit"),
onPressed: () {
String text = _controller.text.toString();
if (!text.contains("https://")) {
text = "https://" + text;
}
// text here will always have https://
},
),
],
),
Upvotes: 2
Reputation: 7914
As far as I understand, you need something like masked edit, look here: https://github.com/benhurott/flutter-masked-text/blob/master/README.md
Upvotes: 0