Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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);
             }
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading