wemersonrv

InputField

Jul 9th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.39 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:flutter/widgets.dart';
  4.  
  5. class InputField extends StatelessWidget {
  6.   final IconData icon;
  7.   final String hint;
  8.   final bool obscure;
  9.   final Stream<String> stream;
  10.   final Function(String) onChanged;
  11.  
  12.   const InputField({
  13.     Key key,
  14.     this.icon,
  15.     this.hint,
  16.     this.obscure,
  17.     this.stream,
  18.     this.onChanged,
  19.   }) : super(key: key);
  20.  
  21.   @override
  22.   Widget build(BuildContext context) {
  23.     return StreamBuilder<String>(
  24.       stream: stream,
  25.       initialData: "",
  26.       builder: (context, snapshot) {
  27.         print("Stream data: ${snapshot.data}");
  28.  
  29.         return TextField(
  30.           onChanged: onChanged,
  31.           decoration: InputDecoration(
  32.             icon: Icon(icon, color: Colors.grey[600]),
  33.             hintText: hint,
  34.             hintStyle: TextStyle(color: Colors.grey[600]),
  35.             focusedBorder: UnderlineInputBorder(
  36.               borderSide: BorderSide(color: Colors.green),
  37.             ),
  38.             contentPadding: EdgeInsets.only(
  39.               left: 5,
  40.               right: 30,
  41.               bottom: 30,
  42.               top: 30,
  43.             ),
  44.             errorText: snapshot.hasError ? snapshot.error : null,
  45.           ),
  46.           style: TextStyle(color: Colors.grey[600]),
  47.           obscureText: obscure,
  48.         );
  49.       },
  50.     );
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment