'Every time I focus on TextField or TextFormField the screen reload and then the App freeze
This is my code, every time I click on TexFormField, giving focus to it, the page reload with this error in debug:
I/AssistStructure(16650): Flattened final assist data: 484 bytes, containing 1 windows, 3 views.
Then the App froze. I cannot be very sure but it seems happening since the last upgrade to the Flutter version. Looking on the Net this can be related to a rebuild, but this seems not the case.
Could someone help ?
class Profile extends StatefulWidget {
const Profile({Key? key}) : super(key: key);
@override
State createState() {
return ProfileState();
}
}
class ProfileState extends State<Profile> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
],
)
);
}
}
Solution 1:[1]
I tried to run your code on an Android emulator. However, I couldn't reproduce the error. TextFormField was focused without lags. P.S. I'm using master channel (2.13.0-0.0.pre.1002)
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: ProfileScreen()
);
}
}
class ProfileScreen extends StatelessWidget {
const ProfileScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Profile'),
centerTitle: true,
),
body:const Profile()
);
}
}
class Profile extends StatefulWidget {
const Profile({Key? key}) : super(key: key);
@override
State createState() {
return ProfileState();
}
}
class ProfileState extends State<Profile> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
],
)
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Behzod Faiziev |
