How to append a unique code to the input of textfield in flutter?

Viewed 266

I have a textfield to accept username and in that i want to add an input formatter or any other stuff to add my unique code at the end of it. For example the user enters "Jack" then in my text field i want to show --> "Jack1bh" here 1bh is my unique code.

1 Answers

You can generate a unique id using uuid: ^3.0.5, then you can append the input string with a generated unique id. Here is an official example.

dependencies:
  uuid: 3.0.5

import package

import 'package:uuid/uuid.dart';

var uuid = Uuid();

Then create some ids ...

// Generate a v1 (time-based) id
uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'

// Generate a v4 (random) id
uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1'

// Generate a v5 (namespace-name-sha1-based) id
uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c'
Related