import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';

Color _white = const Color(0xFFFFFFFF);

class LoginScreen extends StatefulWidget {
  static const routeName = 'login';

  const LoginScreen({Key? key}) : super(key: key);

  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
  //textinput related
  final email = TextEditingController();
  final password = TextEditingController();

  @override
  void dispose() {
    // Clean up the controller when the widget is disposed.
    email.dispose();
    password.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return PlatformScaffold(
      body: Stack(
        children: <Widget>[
          Container(
              height: double.infinity,
              width: double.infinity,
              color: const Color(0xFF2E7D32)),
          Column(children: [
            Expanded(
              flex: 1,
              child: Padding(
                  padding: const EdgeInsets.symmetric(
                      horizontal: 15.0, vertical: 0.0),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        'Sign In',
                        style: TextStyle(
                          color: _white,
                          fontSize: 30.0,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      Padding(
                          padding: const EdgeInsets.symmetric(
                              horizontal: 0.0, vertical: 15.0),
                          child: _buildInputField(
                              controller: email, label: 'Email')),
                      Padding(
                          padding: const EdgeInsets.symmetric(
                              horizontal: 0.0, vertical: 15.0),
                          child: _buildInputField(
                              controller: password,
                              label: 'Password',
                              obscureText: true)),
                      _buildButton(label: 'Login', onPressed: null),
                      _buildButton(label: 'Sign Up', onPressed: null)
                    ],
                  )),
            ),
            const Padding(
                padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 10.0),
                child: Text(
                  '© 2021 Agineek. | All rights reserved',
                  style: TextStyle(
                      color: Color(0xFFFFFFFF), fontWeight: FontWeight.bold),
                ))
          ]),
        ],
      ),
    );
  }

  Padding _buildButton(
      {required String label, required VoidCallback? onPressed}) {
    return Padding(
        padding: const EdgeInsets.symmetric(horizontal: 0.0, vertical: 15.0),
        child: SizedBox(
            width: double.infinity,
            height: 50.0,
            child: PlatformButton(
              onPressed: onPressed,
              child: PlatformText(
                label,
                style: TextStyle(
                    color: _white,
                    letterSpacing: 2.0,
                    fontSize: 18.0,
                    fontWeight: FontWeight.bold),
              ),
            )));
  }

  PlatformTextField _buildInputField(
      {required TextEditingController controller,
      required String label,
      bool obscureText = false}) {
    return PlatformTextField(
        material: (_, __) => MaterialTextFieldData(
            controller: controller,
            maxLines: 1,
            decoration: InputDecoration(
                labelText: label, labelStyle: TextStyle(color: _white))),
        cupertino: (_, __) => CupertinoTextFieldData(
            controller: controller, maxLines: 1, placeholder: label));
  }
}
