iws_form_bloc 1.5.1 copy "iws_form_bloc: ^1.5.1" to clipboard
iws_form_bloc: ^1.5.1 copied to clipboard

unlistedoutdated

Simplified creation of forms and listings using the BLoC pattern.

Simplified creation of forms and listings using the BLoC pattern.

Forms #

BLoC #

import 'package:iws_form_bloc/iws_form_bloc.dart';

class LoginBloc extends FormBloc {
    
    final email = TextFieldBloc(name: 'email', validators: [Validators email]);
    final password = TextFieldBloc(name: 'password', validators: [Validators.password]);

    LoginBloc() {
        addFieldBlocs(fieldBlocs: [email, password]);
    }

    @override
    void onSubmitting(Emitter<FormBlocState> emit) async {
        //TODO: Add logic
    }

}

Widget #

    FormBlocConsumer<LoginBloc>(
      loadFaild: const Center(child: Text('Error loading form')),
      onFailure: (context, state) {
        ScaffoldMessenger.of(context).showSnackBar(SnackBar(
            content: Text(
                state.failureResponse?.message ?? 'Please check the data')));
      },
      onSuccess: (context, state) =>
          Navigator.pushReplacementNamed(context, 'home'),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
        child: Column(
          children: [
            const Text(
              'Login',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
            ),
            TextFieldBlocBuilder<LoginBloc>(
              bloc: bloc,
              blocField: bloc.email,
              autofocus: true,
              inputType: TextInputType.emailAddress,
              textInputAction: TextInputAction.next,
              label: 'e-mail',
              prefixIcon: const Icon(Icons.email),
            ),
            PasswordFieldBlocBuilder<LoginBloc>(
                bloc: bloc,
                blocField: bloc.password,
                label: 'Password',
                prefixIcon: const Icon(Icons.password),
                textInputAction: TextInputAction.go,
                textEditingController: _passwordController,
                onSubmitted: (v) => bloc.submit()),
            const SizedBox(height: 20.0),
            ConstrainedBox(
              constraints: const BoxConstraints.tightFor(
                  width: double.infinity, height: 40),
              child: FilledButton(
                child: const Text('LOGIN'),
                onPressed: () => bloc.submit(),
              ),
            ),
          ],
        ),
      ),
    );

List #

bloc = ListBloc(
    provider: IwsHttpModel(
        path: 'users',
        iwsHttp: IwsHttp(),
        toJson: User.toJson,
        fromJson: User.fromJson)
    );

BlocProvider<ListBloc<User>>(
    create: (context) => bloc,
    child: BlocBuilder<ListBloc<User>, ListState<User>>(
        builder: (context, state) {
            switch (state.status) {
                case ListStatus.failure:
                return Center(
                    child: Text(state.error?.error ?? 'Unknown error'));
                case ListStatus.success:
                case ListStatus.getting:
                return ListView.builder(
                    itemBuilder: (BuildContext context, int index) =>
                        _userDetail(state.list[index]),
                    itemCount: state.list.length,
                    padding: const EdgeInsets.only(
                        bottom: 70.0, left: 10.0, right: 10.0, top: 10.0));
                case ListStatus.initial:
                return const CircularProgressIndicator();
            }
        },
    ),
);
0
likes
120
points
597
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Simplified creation of forms and listings using the BLoC pattern.

Homepage

License

MIT (license)

Dependencies

bloc, flutter, flutter_bloc, iws_http, iws_http_model

More

Packages that depend on iws_form_bloc