Я не уверен, что вы пытаетесь достичь, но вот простой код, который вы можете попробовать, который не генерирует новый номер после проверки правильности ввода или нет, а также имеет новую кнопку генерации номера
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Pageone(),
),
);
}
}
class Pageone extends StatefulWidget {
@override
_PageoneState createState() => _PageoneState();
}
class _PageoneState extends State<Pageone> {
TextEditingController controller = TextEditingController();
int a = Random().nextInt(10);
int b = Random().nextInt(10);
int c;
String result;
@override
void initState() {
plus();
super.initState();
}
void plus() {
c = a + b;
}
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
SizedBox(
width: 10,
),
Text(
'$a',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 100,
color: Color(0xff52de97),
letterSpacing: 0.5),
),
Text(
'$b',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 100,
color: Color(0xff52de97),
),
),
Text(
'$c',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 100,
color: Color(0xff52de97),
letterSpacing: 0.5,
),
),
SizedBox(
width: 10,
),
],
),
Form(
child: Column(
children: <Widget>[
Container(
width: 300,
child: TextFormField(
controller: controller,
onFieldSubmitted: (String value) {
setState(() =>
result = int.parse(value) == c ? 'true' : 'false');
},
),
),
],
),
),
Text(
result == null ? '' : '$result',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 100,
color: Color(0xff52de97),
letterSpacing: 0.5),
),
MaterialButton(
child: Text('Generate new'),
onPressed: () {
setState(() {
a = Random().nextInt(10);
b = Random().nextInt(10);
plus();
});
},
),
],
),
);
}
}