Guest User

My source code

a guest
Feb 24th, 2019
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.82 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:wedding_app/models/constants/colors.dart';
  3. import 'package:wedding_app/models/state/guest_list/guest_widget.dart';
  4.  
  5. class GuestPage extends GuestState {
  6.   String name;
  7.   TextEditingController _editingController = TextEditingController();
  8.  
  9.   // Create a global key that will uniquely identify the Form widget and allow
  10.   // us to validate the form
  11.   //
  12.   // Note: This is a `GlobalKey<FormState>`, not a GlobalKey<MyCustomFormState>!
  13.   final _formKey = GlobalKey<FormState>();
  14.  
  15.   @override
  16.   void dispose() {
  17.     _editingController.dispose();
  18.     super.dispose();
  19.   }
  20.  
  21.   @override
  22.   Widget build(BuildContext context) {
  23.     double textboxSize = MediaQuery.of(context).size.height / 1.6;
  24.  
  25.     return Form(
  26.         key: _formKey,
  27.         child: Scaffold(
  28.             body: Builder(
  29.                 builder: (context) => Container(
  30.                     height: textboxSize * 10,
  31.                     child: Container(
  32.                       padding: EdgeInsets.all(30),
  33.                       child: Column(
  34.                         crossAxisAlignment: CrossAxisAlignment.center,
  35.                         children: buildForm(context),
  36.                       ),
  37.                     ))))); // How do I prevent these??
  38.   }
  39.  
  40.   List<Widget> buildForm(BuildContext context) {
  41.     return <Widget>[
  42.       Column(
  43.         crossAxisAlignment: CrossAxisAlignment.start,
  44.         children: <Widget>[
  45.           Container(
  46.               child: Padding(
  47.                   padding: EdgeInsets.only(bottom: 2),
  48.                   child: Text(
  49.                     "First Name",
  50.                     style: TextStyle(fontFamily: "acme", fontSize: 20),
  51.                   ))), // How do I prevent these??
  52.           TextFormField(
  53.             textAlign: TextAlign.left,
  54.             maxLength: 40,
  55.             style: TextStyle(height: 2, fontSize: 15, color: Colors.black87),
  56.             controller: _editingController,
  57.             validator: (value) {
  58.               if (value.isEmpty) {
  59.                 return "Please enter a first name";
  60.               }
  61.  
  62.               name = value;
  63.             },
  64.           )
  65.         ],
  66.       ),
  67.       Column(
  68.         crossAxisAlignment: CrossAxisAlignment.start,
  69.         children: <Widget>[
  70.           Container(
  71.             child: Text(
  72.               "Last Name",
  73.               style: TextStyle(fontFamily: "acme", fontSize: 20),
  74.             ),
  75.           ),
  76.           TextFormField(
  77.             maxLength: 40,
  78.             textAlign: TextAlign.start,
  79.             style: TextStyle(height: 2, fontSize: 15, color: Colors.black87),
  80.           )
  81.         ],
  82.       ),
  83.       Padding(
  84.           padding: EdgeInsets.only(top: 15.0),
  85.           child: ButtonTheme(
  86.               minWidth: 200,
  87.               height: 50,
  88.               child: new RaisedButton(
  89.                 color: ApplicationColors.black,
  90.                 textColor: ApplicationColors.ivory,
  91.                 shape: RoundedRectangleBorder(
  92.                     borderRadius: BorderRadius.circular(30.0)),
  93.                 onPressed: () {
  94.                   if (_formKey.currentState.validate()) {
  95.                     _showToast(context, "valid");
  96.                   }
  97.                 },
  98.                 child: Text("Submit",
  99.                     style: new TextStyle(
  100.                         color: ApplicationColors.ivory,
  101.                         fontFamily: 'Acme',
  102.                         fontSize: 20)), // How do I prevent these??
  103.               ))) // How do I prevent these??
  104.     ];
  105.   }
  106.  
  107.   void _showToast(BuildContext context, String text) {
  108.     final scaffold = Scaffold.of(context);
  109.     scaffold.showSnackBar(
  110.       SnackBar(
  111.         content: Text(text),
  112.         action: SnackBarAction(
  113.             label: 'UNDO', onPressed: scaffold.hideCurrentSnackBar),
  114.       ),
  115.     );
  116.   }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment