Skip to content

Instantly share code, notes, and snippets.

@rifkyputra
Created April 21, 2022 11:29
Show Gist options
  • Save rifkyputra/bb25d5a31c76cf0c702fb60f52a469ac to your computer and use it in GitHub Desktop.
Save rifkyputra/bb25d5a31c76cf0c702fb60f52a469ac to your computer and use it in GitHub Desktop.
register user
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