:::

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%3Ftbsn%3D42%26tbdsn%3D1898

計數器

今天: 1975197519751975
昨天: 4038403840384038
總計: 5565938556593855659385565938556593855659385565938