From d0d3f9476bf8c1392cfbab1b036c599e531d88a5 Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Sun, 16 Apr 2023 11:34:01 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/guess/guess_app_bar.dart | 48 ++++++++++++++++++++++++ lib/guess/guess_page.dart | 71 +++++------------------------------- lib/guess/result_notice.dart | 26 +++++++++++++ 3 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 lib/guess/guess_app_bar.dart create mode 100644 lib/guess/result_notice.dart diff --git a/lib/guess/guess_app_bar.dart b/lib/guess/guess_app_bar.dart new file mode 100644 index 0000000..8fcb0e8 --- /dev/null +++ b/lib/guess/guess_app_bar.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class GuessAppBar extends StatelessWidget implements PreferredSizeWidget{ + const GuessAppBar({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return AppBar( + systemOverlayStyle: const SystemUiOverlayStyle( + statusBarIconBrightness: Brightness.dark, + statusBarColor: Colors.transparent), + // leadingWidth: 54, + titleSpacing: 0, + leading: Icon( + Icons.menu, + color: Colors.black, + ), + actions: [ + IconButton( + splashRadius: 20, + onPressed: () {}, + icon: Icon( + Icons.run_circle_outlined, + color: Colors.blue, + )) + ], + backgroundColor: Colors.white, + elevation: 0, + title: TextField( + keyboardType: TextInputType.number, + decoration: InputDecoration( + filled: true, + fillColor: Color(0xffF3F6F9), + constraints: BoxConstraints(maxHeight: 35), + border: UnderlineInputBorder( + borderSide: BorderSide.none, + borderRadius: BorderRadius.all(Radius.circular(6)), + ), + hintText: "输入 0~99 数字", + hintStyle: TextStyle(fontSize: 14)), + ), + ); + } + + @override + Size get preferredSize => const Size.fromHeight(kToolbarHeight); +} diff --git a/lib/guess/guess_page.dart b/lib/guess/guess_page.dart index 4a73fd4..3be9140 100644 --- a/lib/guess/guess_page.dart +++ b/lib/guess/guess_page.dart @@ -2,6 +2,8 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'guess_app_bar.dart'; +import 'result_notice.dart'; class GuessPage extends StatefulWidget { const GuessPage({super.key, required this.title}); @@ -26,77 +28,22 @@ class _GuessPageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: - AppBar( - systemOverlayStyle: SystemUiOverlayStyle( - statusBarIconBrightness: Brightness.dark, - statusBarColor: Colors.transparent - ), - // leadingWidth: 54, - titleSpacing: 0, - - leading: Icon(Icons.menu, color: Colors.black,), - actions: [ - IconButton( - splashRadius: 20, - onPressed: (){}, icon: Icon( - Icons.run_circle_outlined, - color: Colors.blue, - )) - ], - backgroundColor: Colors.white, - elevation: 0, - title: - TextField( - keyboardType: TextInputType.number, - decoration: InputDecoration( - filled: true, - fillColor: Color(0xffF3F6F9), - constraints: BoxConstraints(maxHeight: 35), - border: UnderlineInputBorder( - borderSide: BorderSide.none, - borderRadius: BorderRadius.all(Radius.circular(6)), - ), - hintText: "输入 0~99 数字", - hintStyle: TextStyle(fontSize: 14)), - ), - ), + appBar: GuessAppBar(), body: Stack( children: [ Column( children: [ - Expanded( - child: Container( - alignment: Alignment.center, - color: Colors.redAccent, - child: Text( - '大了', - style: TextStyle( - fontSize: 54, - color: Colors.white, - fontWeight: FontWeight.bold), - ), - )), - // Spacer(), - Expanded( - child: Container( - alignment: Alignment.center, - color: Colors.blueAccent, - child: Text( - '小了', - style: TextStyle( - fontSize: 54, - color: Colors.white, - fontWeight: FontWeight.bold), - ), - )), + ResultNotice(color:Colors.redAccent,info:'大了'), + ResultNotice(color:Colors.blueAccent,info:'小了'), ], ), Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text('点击生成随机数值',), + const Text( + '点击生成随机数值', + ), Text( '$_value', style: Theme.of(context).textTheme.headlineMedium, @@ -113,4 +60,4 @@ class _GuessPageState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/guess/result_notice.dart b/lib/guess/result_notice.dart new file mode 100644 index 0000000..65fdccb --- /dev/null +++ b/lib/guess/result_notice.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; + +class ResultNotice extends StatelessWidget { + final Color color; + final String info; + + const ResultNotice({ + Key? key, + required this.color, + required this.info, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Expanded( + child: Container( + alignment: Alignment.center, + color: color, + child: Text( + info, + style: TextStyle( + fontSize: 54, color: Colors.white, fontWeight: FontWeight.bold), + ), + )); + } +}