2 Commits 363405c6f9 ... 36c161cb55

Tác giả SHA1 Thông báo Ngày
  juan 36c161cb55 fix?? 1 tháng trước cách đây
  juan 747f84a2b7 made tabs for each result, (they return all not found for now) 1 tháng trước cách đây
3 tập tin đã thay đổi với 205 bổ sung14 xóa
  1. 44 14
      lib/home_page.dart
  2. 160 0
      lib/login.dart
  3. 1 0
      pubspec.yaml

+ 44 - 14
lib/home_page.dart

@@ -9,35 +9,63 @@ class HomeScreen extends StatefulWidget {
   _HomeScreenState createState() => _HomeScreenState();
 }
 
-class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
+class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
   final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
   final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
   ApiService apiService = ApiService();
   bool _isSidebarOpen = true;
   bool querySearches = false;
 
-  List<String> _tabs = ['INBOX', 'Search'];
+  List<String> _tabs = ['INBOX'];
+  Map<String, Widget> _tabWidgets = {};
   TabController? _tabController;
 
   @override
   void initState() {
     super.initState();
     _tabController = TabController(length: _tabs.length, vsync: this);
+    _tabWidgets['INBOX'] = EmailPage(
+      key: _emailPageKey,
+    );
   }
-   // Add a new tab based on the search
+
+  // Add a new tab based on the search
   void _performSearch(String query) {
     setState(() {
-      _tabs.add(query);
-      _tabController = TabController(length: _tabs.length, vsync: this);
+      if (!_tabs.contains(query)) {
+        _tabs.add(query);
+        _tabWidgets[query] = _buildSearchResultsWidget(
+            query); // Store a different widget for this tab
+        _tabController = TabController(length: _tabs.length, vsync: this);
+      }
     });
   }
 
   // Remove a tab
   void _removeTab(int index) {
-    setState(() {
-      _tabs.removeAt(index);
-      _tabController = TabController(length: _tabs.length, vsync: this);
-    });
+    if (_tabs[index] != 'INBOX') {
+      setState(() {
+        String tabToRemove = _tabs[index];
+        _tabs.removeAt(index);
+        _tabWidgets
+            .remove(tabToRemove); // Remove widget associated with the tab
+        _tabController = TabController(length: _tabs.length, vsync: this);
+      });
+    }
+  }
+
+  // Build a custom widget for each search query
+  Widget _buildSearchResultsWidget(String query) {
+    return Center(
+      child: Column(
+        mainAxisAlignment: MainAxisAlignment.center,
+        children: [
+          Text("Results for: $query", style: TextStyle(fontSize: 24)),
+          // You can add a list or any custom widget here
+          Text("Here you can display search results or other content."),
+        ],
+      ),
+    );
   }
 
   @override
@@ -46,7 +74,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
     super.dispose();
   }
 
-
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -166,7 +193,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
                                 // setState(() {
                                 //   querySearches = true;
                                 // });
-
                               },
                             ),
                           ),
@@ -230,7 +256,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
                             },
                             child: Icon(Icons.navigate_next),
                           ),
-                          
                         ],
                       ),
                     ),
@@ -238,11 +263,16 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
                       child: TabBarView(
                         controller: _tabController,
                         children: _tabs.map((tab) {
-                          return Center(child: EmailPage(key: _emailPageKey,));
+                          return _tabWidgets[tab] ??
+                              Center(child: Text("No content found"));
+                          // return Center(
+                          //     child: EmailPage(
+                          //   key: _emailPageKey,
+                          // ));
                         }).toList(),
                       ),
                     ),
-                    
+
                     // if (_tabs.isEmpty)
                     //   Expanded(
                     //     child: EmailPage(key: _emailPageKey),

+ 160 - 0
lib/login.dart

@@ -0,0 +1,160 @@
+import 'dart:convert';
+import 'package:flutter/material.dart';
+import 'package:http/http.dart' as http;
+
+class AuthService {
+  Future<bool> isUserLoggedIn() async {
+    try {
+      var url = Uri.http('127.0.0.1:3001', 'is_logged_in');
+      var response = await http.get(url);
+      print(response.body);
+      if (response.statusCode == 200) {
+        print('all good in the east!');
+        List json = jsonDecode(response.body);
+        print(json[0]);
+        return true;
+      }
+    } catch (e) {
+      print(e);
+    }
+    return false;
+  }
+}
+
+class LoginPage extends StatefulWidget {
+  const LoginPage({super.key});
+
+  @override
+  _LoginPageState createState() => _LoginPageState();
+}
+
+class _LoginPageState extends State<LoginPage> {
+  final AuthService _authService = AuthService();
+  // Controllers for capturing user input
+  final TextEditingController _emailController = TextEditingController();
+  final TextEditingController _passwordController = TextEditingController();
+
+  // Key to identify the form
+  final _formKey = GlobalKey<FormState>();
+
+  void checkLogin() async {
+    // try {
+    //   var url = Uri.http('127.0.0.1:3001', 'is_logged_in');
+    //   var response = await http.get(url);
+    //   print(response.body);
+    //   if (response.statusCode == 200) {
+    //     print('all good on the west');
+    //   }
+    // } catch (e) {
+    //   print(e);
+    // }
+    bool isLoggedIn = await _authService.isUserLoggedIn();
+    
+  }
+
+  // Function to handle login action
+  void _handleLogin() {
+    if (_formKey.currentState!.validate()) {
+      // Perform login action (e.g., authenticate with backend)
+      String email = _emailController.text;
+      String password = _passwordController.text;
+
+      // For demonstration, just print the values
+      print('Email: $email');
+      print('Password: $password');
+
+      // Clear the input fields
+      _emailController.clear();
+      _passwordController.clear();
+    }
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(
+        title: const Text('Login Page'),
+      ),
+      body: Padding(
+        padding: const EdgeInsets.all(16.0),
+        child: Form(
+          key: _formKey,
+          child: Align(
+            alignment: Alignment.centerLeft,
+            child: Column(
+              mainAxisSize: MainAxisSize.min,
+              crossAxisAlignment: CrossAxisAlignment.start,
+              children: [
+                Text('Sign in to your email'),
+                SizedBox(
+                  height: 5,
+                ),
+                // Email Field
+                Container(
+                  width: 200,
+                  child: TextFormField(
+                    controller: _emailController,
+                    decoration: const InputDecoration(
+                      labelText: 'Email',
+                      hintText: 'Enter your email',
+                      helperMaxLines: 1,
+                    ),
+                    validator: (value) {
+                      // Simple email validation
+                      if (value == null || value.isEmpty) {
+                        return 'Please enter your email';
+                      }
+                      if (!RegExp(r'^\S+@\S+\.\S+$').hasMatch(value)) {
+                        return 'Please enter a valid email address';
+                      }
+                      return null;
+                    },
+                  ),
+                ),
+                const SizedBox(height: 16.0),
+                // Password Field
+                Container(
+                  width: 200,
+                  child: TextFormField(
+                    controller: _passwordController,
+                    decoration: const InputDecoration(
+                      labelText: 'Password',
+                      hintText: 'Enter your password',
+                    ),
+                    obscureText: true, // Hide the password text
+                    validator: (value) {
+                      // Simple password validation
+                      if (value == null || value.isEmpty) {
+                        return 'Please enter your password';
+                      }
+                      if (value.length < 6) {
+                        return 'Password must be at least 6 characters long';
+                      }
+                      return null;
+                    },
+                  ),
+                ),
+                const SizedBox(height: 32.0),
+                // Login Button
+                SizedBox(
+                  width: 200,
+                  child: ElevatedButton(
+                    onPressed: _handleLogin,
+                    child: const Text('Login'),
+                  ),
+                ),
+                SizedBox(
+                  width: 200,
+                  child: ElevatedButton(
+                    onPressed: checkLogin,
+                    child: const Text('checker'),
+                  ),
+                )
+              ],
+            ),
+          ),
+        ),
+      ),
+    );
+  }
+}

+ 1 - 0
pubspec.yaml

@@ -18,6 +18,7 @@ dependencies:
 
   english_words: ^4.0.0
   provider: ^6.0.0
+  intl: ^0.19.0
 
 dev_dependencies:
   flutter_test: