Created
April 21, 2022 11:29
-
-
Save rifkyputra/bb25d5a31c76cf0c702fb60f52a469ac to your computer and use it in GitHub Desktop.
register user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RegisterUserPage extends StatefulWidget { | |
| const RegisterUserPage({Key? key}) : super(key: key); | |
| static const String routeName = 'RegisterUserPage'; | |
| @override | |
| State<RegisterUserPage> createState() => _RegisterUserPageState(); | |
| } | |
| class _RegisterUserPageState extends State<RegisterUserPage> { | |
| final TextEditingController textEditingController = TextEditingController(); | |
| String username = ''; | |
| @override | |
| Widget build(BuildContext context) { | |
| return BlocListener<AppCubit, AppState>( | |
| listener: (context, state) { | |
| if (state.username != null) { | |
| Navigator.of(context).pushNamed(ChatRoomPage.routeName); | |
| } | |
| }, | |
| child: Scaffold( | |
| body: Column( | |
| crossAxisAlignment: CrossAxisAlignment.center, | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [ | |
| TextField( | |
| controller: textEditingController, | |
| decoration: const InputDecoration( | |
| hintText: 'Enter Username', | |
| ), | |
| onChanged: (value) => setState(() => username = value), | |
| ), | |
| const SizedBox(height: 40), | |
| ElevatedButton( | |
| onPressed: () => context.read<AppCubit>().saveUsername(username), | |
| style: ElevatedButton.styleFrom( | |
| shape: const StadiumBorder(), | |
| ), | |
| child: Text('Enter'), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment