The key inside AES() does not accept because The instance member 'key' can't be accessed in an initializer.Try replacing the reference to the instance member with a different expression
import 'package:encrypt/encrypt.dart' ;
class className extends StatefulWidget {
className({Key? key}) : super(key: key);
@override
_className createState() => _classNameState();
}
class _classNameState extends State<className> {
final iv =IV.fromLength(16);
var key = Key.fromUtf8('b75524255a7f54d2726a951bb39204df');
final encrypter = Encrypter(AES(key));
CodePudding user response:
You can't instantiate key
during the declaration.
Just declare key
and instantiate it in a second moment (for example in the initState()
).
CodePudding user response:
You cannot initialize a member variable (key
) and then proceed to use it in the initialization of another member variable (encrypter
). The simplest fix is to add the late
keyword before the encrypted
initialization.
late final encrypter = Encrypter(AES(key));