how to get a textfield value and convert the value into md5 encryption in flutter?

Advertisements

My code:

Center(
  child: SizedBox(
    height: height * 0.08,
    width: width - 35,
    child: TextFormField(
      controller: passwordController,
      validator: (password) {
        if (password == null || password.isEmpty) {
          return "Please enter your password";
        }
        return null;
      },
      onChanged: (value) {
        setState(() {
          password1 = value;
        });
      },
      obscureText: passwordVisible,
      obscuringCharacter: "*",
      decoration: InputDecoration(
        border: const OutlineInputBorder(),
        enabledBorder: const OutlineInputBorder(borderSide: BorderSide(color: Colors.black)),
        focusedBorder: const OutlineInputBorder(
          borderSide: BorderSide(color: Colors.blueAccent),
        ),
        prefixIcon: const Icon(Icons.lock_open, color: Colors.blueAccent),
        labelText: password,
        labelStyle: const TextStyle(color: Colors.grey, fontSize: 13.0),
        suffixIcon: IconButton(
          icon: Icon(passwordVisible ? Icons.visibility : Icons.visibility_off),
          onPressed: () {
            setState(() {
              passwordVisible = !passwordVisible;
            });
          },
        ),
      ),
    ),
  ),
),

This is the actual code. I want get the value of this filled and convert the value into MD5 encryption in Flutter.

>Solution :

you can try to use this Crypto and convert package to convert to MD5

import 'dart:convert';
import 'package:crypto/crypto.dart';

var md5password=""; // var to store md5 password  

String generateMd5(String input) {
  return md5.convert(utf8.encode(input)).toString();
}




TextFormField(
onChanged: (value) { 
            setState(() { password1 = value; });
         md5password=generateMd5(password1);
             }
)

Leave a Reply Cancel reply