text_field_options_values 0.0.1 copy "text_field_options_values: ^0.0.1" to clipboard
text_field_options_values: ^0.0.1 copied to clipboard

Text input with optionals.

example/lib/main.dart

import 'dart:ui';

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'TextFieldOptionsValues',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: '111Package TextFieldOptionsValues'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var dataForm = {"value": "", "option": ""};
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
          child: Form(
        key: _formKey,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            //Incluimo el text field options, como parametro enviamos las opciones de sufijos
            TextFieldOptions(
                // textInitial: "Hola",
                // optionInitial: "KW",
                
                // decorationSelectedOption: const BoxDecoration(
                //     color: Colors.black,
                //     borderRadius: BorderRadius.all(Radius.circular(5))),
                
                // decorationUnselectedOption: const BoxDecoration(
                //     color: Colors.white,
                //     borderRadius: BorderRadius.all(Radius.circular(5))),

                // textStyleSelectedOption: const TextStyle(color: Colors.white),
                // textStyleUnselectedOption: const TextStyle(color: Colors.red),
                
                margin: const EdgeInsets.all(20),

                validator: (String value, String option) {
                  debugPrint(value);
                  debugPrint(option);

                  dataForm["value"] = value;
                  dataForm["option"] = option;
                  //Validamos
                  // if (value.isEmpty || option.isEmpty) {
                  //   return "Datos incorrectos";
                  // }
                  //Si los valores son correcto validamos asignamos los valores para imprimirlos
                },
                options: ["Cº", "Fº"]),
            
            TextFieldOptions(
                // textInitial: "Hola",
                // optionInitial: "KW",
                
                // decorationSelectedOption: const BoxDecoration(
                //     color: Colors.black,
                //     borderRadius: BorderRadius.all(Radius.circular(5))),
                
                // decorationUnselectedOption: const BoxDecoration(
                //     color: Colors.white,
                //     borderRadius: BorderRadius.all(Radius.circular(5))),

                // textStyleSelectedOption: const TextStyle(color: Colors.white),
                // textStyleUnselectedOption: const TextStyle(color: Colors.red),
                
                validator: (String value, String option) {
                  debugPrint(value);
                  debugPrint(option);

                  dataForm["value"] = value;
                  dataForm["option"] = option;
                  //Validamos
                  if (value.isEmpty || option.isEmpty) {
                    return "Datos incorrectos";
                  }
                  //Si los valores son correcto validamos asignamos los valores para imprimirlos
                },
                options: ["Cº", "Fº"]),
           
            ElevatedButton(
                onPressed: () {
                  if (!_formKey.currentState!.validate()) {
                    debugPrint("Error");
                  }

                  setState(() {
                    //Actualizamos para visualizar los valores encaso de que esten correctos
                  });
                },
                child: const Text("Submit")),
            const SizedBox(
              height: 30,
            ),
            const Text("Data from",
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600)),
            const SizedBox(
              height: 20,
            ),
            const Text("Value",
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.w300)),
            Text(
              dataForm['value'].toString(),
              style: const TextStyle(fontSize: 25, fontWeight: FontWeight.w600),
            ),
            const SizedBox(
              height: 20,
            ),
            const Text("Option Selected",
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.w300)),
            Text(dataForm['option'].toString(),
                style:
                    const TextStyle(fontSize: 25, fontWeight: FontWeight.w600)),
          ],
        ),
      )), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
0
likes
110
pub points
0%
popularity

Publisher

unverified uploader

Text input with optionals.

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on text_field_options_values