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.

Revisions

  1. rifkyputra created this gist Apr 21, 2022.
    47 changes: 47 additions & 0 deletions register_user_page.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    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'),
    ),
    ],
    ),
    ),
    );
    }
    }