:::

6-11 表單

class _SignInState extends State<SignIn> {
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  String email;
  String passwd;

  InputDecoration myInputDecoration = InputDecoration(
    fillColor: Colors.white,
    filled: true,
    focusedBorder: OutlineInputBorder(
      borderSide: BorderSide(color: Colors.lime, width: 2.0),
    ),
    enabledBorder: OutlineInputBorder(
      borderSide: BorderSide(color: Colors.black12, width: 2.0),
    ),
  );


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('登入我的待辦清單'),
      ),
      body: Container(
        child: Form(
          key: _formKey,
          child: Column(
            children: [
              TextFormField(
                onChanged: (val) {
                  setState(() {
                    email = val;
                  });
                },
                validator: (String val) => (val.isEmpty) ? '請輸入電子郵件' : null,
                decoration: myInputDecoration.copyWith(hintText: '請輸入電子郵件'),
              ),
              TextFormField(
                onChanged: (val) {
                  setState(() {
                    passwd = val;
                  });
                },
                obscureText: true,
                validator: (String val) =>
                    (val.length < 6) ? '密碼至少 6 個字' : null,
                decoration: myInputDecoration.copyWith(hintText: '請輸入登入密碼'),
              ),
              ElevatedButton(
                onPressed: () {
                  if (_formKey.currentState.validate()) {
                    print('電子郵件:$email');
                    print('密碼:$passwd');
                  }
                },
                child: Text(
                  '登入',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 20.0,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

 


:::

書籍目錄

展開 | 闔起

快速登入


https%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1898%26tbsn%3D42

計數器

今天: 3785378537853785
昨天: 2489248924892489
總計: 8025767802576780257678025767802576780257678025767