third/testModuleD_1/testmoduleD/lib/username.dart
2025-07-29 14:31:14 +08:00

68 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:testmoduled/Game.dart';
TextEditingController textEditingController = TextEditingController();
class userName extends StatefulWidget {
const userName({super.key});
@override
State<userName> createState() => _userNameState();
}
class _userNameState extends State<userName> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Player Name",style: TextStyle(fontSize: 22,fontWeight: FontWeight.w500,color: Colors.black87),),
SizedBox(height: 80),
Container(
height: 40,
width: 220,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1,color:Colors.black87)
),
child: TextField(
controller: textEditingController,
decoration: InputDecoration(
hintText: "Input your name",
hintStyle: TextStyle(color: Colors.black38,fontSize: 18),
border: InputBorder.none
),
)
),
SizedBox(height: 16,),
myButton(40, 220, "Game Start", Colors.black87,(){
if(textEditingController.value.text.isNotEmpty){
Navigator.of(context).push(MaterialPageRoute(builder: (c)=>Game()));
}
})
],
),
),
);
}
}
myButton(double height,double width,String text,Color backColor,Function()? onTap){
return GestureDetector(
onTap: onTap,
child: Container(
alignment: Alignment.center,
height: height,
width: width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1,color: Colors.black54),
color: backColor
),
child: Text(text,style: TextStyle(fontSize: 14,fontWeight: FontWeight.w500,color: Colors.white))
),
);
}