• POČETNA
  • G Drive
  • Progr 2
  • Progr Mob
  • more...
    • Spacer
      • Spacer
      • Vežba 10 iz Prog. Mob. Uredjaja

      • Podesavanje

        ​

      • Flutter Login App (Hardcoded Credentials)This is a minimal Flutter login app with:
        • Hardcoded username: admin
        • Hardcoded password: password
        • A simple welcome screen after successful login
        You can create a new Flutter project and replace its pubspec.yaml and lib/main.dart with the files below.

        Project structureflutter_login_app/ pubspec.yaml lib/ main.dart
        pubspec.yamlPlace this file at: flutter_login_app/pubspec.yaml
        name: flutter_login_app description: A simple Flutter login app with hardcoded credentials and a welcome screen. publish_to: "none" version: 1.0.0+1 environment: sdk: ">=3.10.0 <4.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.8 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^4.0.0 flutter: uses-material-design: true
        lib/main.dartPlace this file at: flutter_login_app/lib/main.dart
        import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Login Demo', debugShowCheckedModeBanner: false, theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true, ), home: const LoginScreen(), ); } } class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @override State<LoginScreen> createState() => _LoginScreenState(); } class _LoginScreenState extends State<LoginScreen> { final _formKey = GlobalKey<FormState>(); final TextEditingController _usernameController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); // Hardcoded credentials final String _correctUsername = 'admin'; final String _correctPassword = 'password'; bool _isObscure = true; bool _isLoading = false; void _login() async { if (!_formKey.currentState!.validate()) return; final user = _usernameController.text.trim(); final pass = _passwordController.text; setState(() { _isLoading = true; }); // Simulate a small delay (like contacting a server) await Future.delayed(const Duration(milliseconds: 600)); setState(() { _isLoading = false; }); if (user == _correctUsername && pass == _correctPassword) { if (!mounted) return; Navigator.of(context).pushReplacement( MaterialPageRoute( builder: (_) => WelcomeScreen(username: user), ), ); } else { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Invalid username or password'), duration: Duration(seconds: 2), ), ); } } @override void dispose() { _usernameController.dispose(); _passwordController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: SingleChildScrollView( padding: const EdgeInsets.all(24), child: Form( key: _formKey, child: Column( mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.lock_outline, size: 72), const SizedBox(height: 16), const Text( 'Login', style: TextStyle( fontSize: 28, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 24), TextFormField( controller: _usernameController, decoration: const InputDecoration( labelText: 'Username', border: OutlineInputBorder(), ), validator: (value) { if (value == null || value.trim().isEmpty) { return 'Enter username'; } return null; }, ), const SizedBox(height: 16), TextFormField( controller: _passwordController, decoration: InputDecoration( labelText: 'Password', border: const OutlineInputBorder(), suffixIcon: IconButton( icon: Icon( _isObscure ? Icons.visibility_off : Icons.visibility, ), onPressed: () { setState(() { _isObscure = !_isObscure; }); }, ), ), obscureText: _isObscure, validator: (value) { if (value == null || value.isEmpty) { return 'Enter password'; } return null; }, ), const SizedBox(height: 24), SizedBox( width: double.infinity, child: ElevatedButton( onPressed: _isLoading ? null : _login, child: Padding( padding: const EdgeInsets.symmetric(vertical: 12), child: _isLoading ? const SizedBox( height: 18, width: 18, child: CircularProgressIndicator(strokeWidth: 2), ) : const Text( 'LOGIN', style: TextStyle(fontSize: 16), ), ), ), ), const SizedBox(height: 8), const Text( 'Username: admin | Password: password', style: TextStyle(fontSize: 12, color: Colors.grey), textAlign: TextAlign.center, ), ], ), ), ), ), ); } } class WelcomeScreen extends StatelessWidget { final String username; const WelcomeScreen({super.key, required this.username}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Welcome'), ), body: Center( child: Padding( padding: const EdgeInsets.all(24.0), child: Column( mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.check_circle_outline, size: 80), const SizedBox(height: 16), Text( 'Welcome, $username!', style: const TextStyle( fontSize: 26, fontWeight: FontWeight.bold, ), textAlign: TextAlign.center, ), const SizedBox(height: 8), const Text( 'You have successfully logged in.', style: TextStyle(fontSize: 16), textAlign: TextAlign.center, ), const SizedBox(height: 24), ElevatedButton( onPressed: () { // Simple "logout" back to login screen Navigator.of(context).pushReplacement( MaterialPageRoute( builder: (_) => const LoginScreen(), ), ); }, child: const Text('Log out'), ), ], ), ), ), ); } }
        How to use
        1. Create a new Flutter project:
          flutter create flutter_login_app
        2. Replace the generated pubspec.yaml with the one above.
        3. Replace the contents of lib/main.dart with the main.dart code above.
        4. Run the app:
          cd flutter_login_app flutter run
        Login with:
        • Username: admin
        • Password: password
      • Click here to edit.







      • ​
      • ​










      • ​​








      • ​
    • Spacer
  • d96rsd.com
    ©  Dušan Ružić • Built with Weebly.
    AVMSS Kruševac | Odsek tehničko-tehnoloških studija Kruševac