From c2f47dbc6f1ca75b7d69cf2a4139ab9664021f90 Mon Sep 17 00:00:00 2001 From: TIVMOF Date: Wed, 24 Apr 2024 03:39:54 +0300 Subject: [PATCH] Added login page --- flutter_bank_ui/lib/main.dart | 10 +- flutter_bank_ui/lib/pages/login_page.dart | 79 +++++++++ .../Flutter/GeneratedPluginRegistrant.swift | 2 + flutter_bank_ui/pubspec.lock | 160 +++++++++++++++++- flutter_bank_ui/pubspec.yaml | 2 + 5 files changed, 245 insertions(+), 8 deletions(-) create mode 100644 flutter_bank_ui/lib/pages/login_page.dart diff --git a/flutter_bank_ui/lib/main.dart b/flutter_bank_ui/lib/main.dart index 9d0fa90..c0b2f79 100644 --- a/flutter_bank_ui/lib/main.dart +++ b/flutter_bank_ui/lib/main.dart @@ -1,25 +1,21 @@ -// ignore_for_file: prefer_const_constructors - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'pages/home_page.dart'; +import 'pages/login_page.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) .then((_) { - runApp(new MyApp()); + runApp(MyApp()); }); } class MyApp extends StatelessWidget { - const MyApp({super.key}); - @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, - home: HomePage(), + home: LoginPage(), // Always start with the login page ); } } diff --git a/flutter_bank_ui/lib/pages/login_page.dart b/flutter_bank_ui/lib/pages/login_page.dart new file mode 100644 index 0000000..0cab207 --- /dev/null +++ b/flutter_bank_ui/lib/pages/login_page.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; +import 'home_page.dart'; // Adjust if needed + +class LoginPage extends StatefulWidget { + @override + _LoginPageState createState() => _LoginPageState(); +} + +class _LoginPageState extends State { + final TextEditingController _usernameController = TextEditingController(); + final TextEditingController _passwordController = TextEditingController(); + + Future _login() async { + final username = _usernameController.text.trim(); + final password = _passwordController.text.trim(); + + if (username.isEmpty || password.isEmpty) { + // Show an error message + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text("Please enter both username and password")), + ); + return; + } + + // Example backend authentication (adjust endpoint and request parameters as needed) + final response = await http.post( + Uri.parse('https://example.com/api/login'), // Update with your endpoint + headers: {'Content-Type': 'application/json'}, + body: json.encode({ + 'username': username, + 'password': password, + }), + ); + + if (response.statusCode == 200) { + // Successful login, navigate to the Home Page + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (context) => HomePage()), + ); + } else { + // Login failed + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text("Login failed. Please try again.")), + ); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: Text("Login")), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + TextField( + controller: _usernameController, + decoration: InputDecoration(labelText: "Username"), + ), + TextField( + controller: _passwordController, // Corrected variable name + obscureText: true, + decoration: InputDecoration(labelText: "Password"), + ), + SizedBox(height: 16), + ElevatedButton( + onPressed: _login, + child: Text("Login"), + ), + ], + ), + ), + ); + } +} diff --git a/flutter_bank_ui/macos/Flutter/GeneratedPluginRegistrant.swift b/flutter_bank_ui/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..724bb2a 100644 --- a/flutter_bank_ui/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/flutter_bank_ui/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/flutter_bank_ui/pubspec.lock b/flutter_bank_ui/pubspec.lock index e6be8b6..86c9da1 100644 --- a/flutter_bank_ui/pubspec.lock +++ b/flutter_bank_ui/pubspec.lock @@ -105,6 +105,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" flutter: dependency: "direct main" description: flutter @@ -123,6 +139,27 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + http: + dependency: "direct main" + description: + name: http + sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" image: dependency: transitive description: @@ -211,6 +248,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 + url: "https://pub.dev" + source: hosted + version: "2.2.1" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" + url: "https://pub.dev" + source: hosted + version: "2.2.1" petitparser: dependency: transitive description: @@ -219,6 +280,22 @@ packages: url: "https://pub.dev" source: hosted version: "6.0.2" + platform: + dependency: transitive + description: + name: platform + sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec" + url: "https://pub.dev" + source: hosted + version: "3.1.4" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" pointycastle: dependency: transitive description: @@ -235,6 +312,62 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180 + url: "https://pub.dev" + source: hosted + version: "2.2.3" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + sha256: "1ee8bf911094a1b592de7ab29add6f826a7331fb854273d55918693d5364a1f2" + url: "https://pub.dev" + source: hosted + version: "2.2.2" + shared_preferences_foundation: + dependency: transitive + description: + name: shared_preferences_foundation + sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c" + url: "https://pub.dev" + source: hosted + version: "2.3.5" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59" + url: "https://pub.dev" + source: hosted + version: "2.3.2" sky_engine: dependency: transitive description: flutter @@ -336,6 +469,30 @@ packages: url: "https://pub.dev" source: hosted version: "13.0.0" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" + win32: + dependency: transitive + description: + name: win32 + sha256: "0a989dc7ca2bb51eac91e8fd00851297cfffd641aa7538b165c62637ca0eaa4a" + url: "https://pub.dev" + source: hosted + version: "5.4.0" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + url: "https://pub.dev" + source: hosted + version: "1.0.4" xml: dependency: transitive description: @@ -353,4 +510,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.0 <4.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.19.0" diff --git a/flutter_bank_ui/pubspec.yaml b/flutter_bank_ui/pubspec.yaml index f1b1c78..725a2fe 100644 --- a/flutter_bank_ui/pubspec.yaml +++ b/flutter_bank_ui/pubspec.yaml @@ -33,6 +33,8 @@ dependencies: smooth_page_indicator: syncfusion_flutter_charts: ^25.1.41+1 readmore: ^3.0.0 + http: ^1.2.1 + shared_preferences: ^2.2.3 dev_dependencies: flutter_test: sdk: flutter