状态数据与界面更新 -2
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class GuessAppBar extends StatelessWidget implements PreferredSizeWidget{
|
class GuessAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
const GuessAppBar({Key? key}) : super(key: key);
|
final VoidCallback onCheck;
|
||||||
|
final TextEditingController controller;
|
||||||
|
|
||||||
|
const GuessAppBar({
|
||||||
|
Key? key,
|
||||||
|
required this.onCheck,
|
||||||
|
required this.controller,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -10,7 +17,6 @@ class GuessAppBar extends StatelessWidget implements PreferredSizeWidget{
|
|||||||
systemOverlayStyle: const SystemUiOverlayStyle(
|
systemOverlayStyle: const SystemUiOverlayStyle(
|
||||||
statusBarIconBrightness: Brightness.dark,
|
statusBarIconBrightness: Brightness.dark,
|
||||||
statusBarColor: Colors.transparent),
|
statusBarColor: Colors.transparent),
|
||||||
// leadingWidth: 54,
|
|
||||||
titleSpacing: 0,
|
titleSpacing: 0,
|
||||||
leading: Icon(
|
leading: Icon(
|
||||||
Icons.menu,
|
Icons.menu,
|
||||||
@@ -19,7 +25,7 @@ class GuessAppBar extends StatelessWidget implements PreferredSizeWidget{
|
|||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
splashRadius: 20,
|
splashRadius: 20,
|
||||||
onPressed: () {},
|
onPressed: onCheck,
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.run_circle_outlined,
|
Icons.run_circle_outlined,
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
@@ -28,6 +34,7 @@ class GuessAppBar extends StatelessWidget implements PreferredSizeWidget{
|
|||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
title: TextField(
|
title: TextField(
|
||||||
|
controller: controller,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
filled: true,
|
filled: true,
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ class _GuessPageState extends State<GuessPage> {
|
|||||||
Random _random = Random();
|
Random _random = Random();
|
||||||
bool _guessing = false;
|
bool _guessing = false;
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_guessCtrl.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
void _generateRandomValue() {
|
void _generateRandomValue() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_guessing = true;
|
_guessing = true;
|
||||||
@@ -28,10 +35,19 @@ class _GuessPageState extends State<GuessPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditingController _guessCtrl = TextEditingController();
|
||||||
|
|
||||||
|
void _onCheck(){
|
||||||
|
print("=====Check:目标数值:$_value=====${_guessCtrl.text}============");
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: GuessAppBar(),
|
appBar: GuessAppBar(
|
||||||
|
controller: _guessCtrl,
|
||||||
|
onCheck: _onCheck,
|
||||||
|
),
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
// Column(
|
// Column(
|
||||||
|
|||||||
Reference in New Issue
Block a user