UNPKG

fhipster

Version:

A CLI tool to convert JHipster JDL to Flutter GetX services and models.

98 lines (93 loc) 3.36 kB
/** * Generates the content for the Login View. * @returns {string} The Dart code for the LoginView. */ function generateLoginViewTemplate() { return `import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../controllers/login_controller.dart'; class LoginView extends StatelessWidget { const LoginView({Key? key}) : super(key: key); @override Widget build(BuildContext context) { // Put the controller in memory final LoginController controller = Get.put(LoginController()); return Scaffold( appBar: AppBar( title: const Text('Login'), ), body: Center( child: SingleChildScrollView( padding: const EdgeInsets.all(24.0), child: Form( key: controller.formKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( 'Welcome Back!', style: Theme.of(context).textTheme.headlineMedium, textAlign: TextAlign.center, ), const SizedBox(height: 32), TextFormField( controller: controller.usernameController, decoration: const InputDecoration( labelText: 'Username', prefixIcon: Icon(Icons.person_outline), border: OutlineInputBorder(), ), validator: (value) { if (value == null || value.isEmpty) { return 'Please enter your username'; } return null; }, ), const SizedBox(height: 16), TextFormField( controller: controller.passwordController, obscureText: true, decoration: const InputDecoration( labelText: 'Password', prefixIcon: Icon(Icons.lock_outline), border: OutlineInputBorder(), ), validator: (value) { if (value == null || value.isEmpty) { return 'Please enter your password'; } return null; }, ), const SizedBox(height: 24), Obx(() { return ElevatedButton( onPressed: controller.isLoading.value ? null : controller.login, style: ElevatedButton.styleFrom( padding: const EdgeInsets.symmetric(vertical: 16), ), child: controller.isLoading.value ? const SizedBox( height: 24, width: 24, child: CircularProgressIndicator( color: Colors.white, strokeWidth: 3, ), ) : const Text('Login'), ); }), ], ), ), ), ), ); } } `; } module.exports = { generateLoginViewTemplate };