radio_button_form_field 0.0.4 copy "radio_button_form_field: ^0.0.4" to clipboard
radio_button_form_field: ^0.0.4 copied to clipboard

A Flutter Package to create radio buttons as FormFields, each contained in a ListTile with the button as the Leading Widget.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:radio_button_form_field/radio_button_form_field.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: ExampleForm(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class ExampleForm extends StatefulWidget {
  @override
  _ExampleFormState createState() => _ExampleFormState();
}

GlobalKey myFormKey = new GlobalKey();

class _ExampleFormState extends State<ExampleForm> {
  int myNumber;
  String myValue = 'No value saved yet.';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Radio Button Form Field Example'),
      ),
      body: SafeArea(
        child: Form(
          key: myFormKey,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              RadioButtonFormField(
                toggleable: true,
                padding: EdgeInsets.all(8),
                context: context,
                value: 'value',
                display: 'display',
                data: data,
                onSaved: (value) {
                  setState(() {
                    myNumber = value;
                    myValue = value.toString();
                  });
                },
              ),
              FlatButton(
                onPressed: () {
                  _submitForm();
                },
                child: Text('Submit'),
              ),
              Text(myValue)
            ],
          ),
        ),
      ),
    );
  }

  void _submitForm() {
    final FormState formState = myFormKey.currentState;
    if (formState.validate()) {
      formState.save();
      print(myNumber);
    }
  }
}

final List<Map> data = [
  {'value': 1, 'display': 'One'},
  {'value': 2, 'display': 'Two'},
  {'value': 3, 'display': 'Three'}
];
10
likes
40
pub points
0%
popularity

Publisher

unverified uploader

A Flutter Package to create radio buttons as FormFields, each contained in a ListTile with the button as the Leading Widget.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on radio_button_form_field