A Flutter application demonstrating authentication with Supabase, following the MVC (Model-View-Controller) pattern and using GetX for state management and navigation.
- Email/password authentication
- Google Sign-In integration
- User profile display
- Session persistence
- MVC architecture
- Document upload and management
- Automatic document categorization using OpenAI
- Tag-based document organization
- Neomorphic UI design
-
Create a Supabase project
-
Go to Supabase and create a new project
-
Enable Email and Google authentication in the Auth settings
-
Create the necessary tables using the provided SQL scripts:
Profiles Table
create table profiles ( id uuid references auth.users on delete cascade primary key, email text unique not null, name text, avatar_url text, updated_at timestamp with time zone ); -- Create a secure RLS policy alter table profiles enable row level security; create policy "Users can view their own profile" on profiles for select using (auth.uid() = id); create policy "Users can update their own profile" on profiles for update using (auth.uid() = id);
Documents Table and Storage Setup
- Execute the SQL in the
supabase_documents_setup.sqlfile to create the documents table and configure storage
- Execute the SQL in the
-
-
Configure OpenAI API
- Get an API key from OpenAI
- Update the
apiKeyinlib/services/openai_service.dartwith your actual API key
-
Configure your Flutter project
- Update the Supabase URL and anon key in
lib/main.dartwith your Supabase project credentials:await Supabase.initialize( url: 'YOUR_SUPABASE_URL', anonKey: 'YOUR_SUPABASE_ANON_KEY', );
- Update the Supabase URL and anon key in
-
Configure Google Sign-In
- For Android and iOS, follow the Supabase documentation to set up Google Sign-In
-
Install dependencies and run the app
flutter pub get flutter run
The app supports uploading and managing various document types:
- PDF files
- Word documents (.doc, .docx)
- Images (.jpg, .jpeg, .png)
When a document is uploaded:
- The file is stored in Supabase Storage
- OpenAI analyzes the file name and type to generate an appropriate tag
- The file metadata and tag are stored in the documents table
- Documents are automatically organized by tags in the sidebar
The app follows the MVC (Model-View-Controller) pattern:
- Models: Data structures like UserModel and DocumentModel
- Views: UI components in the views directory
- Controllers: Business logic in the controllers directory
GetX is used for:
- State management with reactive variables
- Navigation without context
- Dependency injection
- Add more tags or categories in the OpenAI service prompt
- Customize the UI by updating the neomorphic styling
- Add document search functionality
- Implement document preview for different file types
This project uses environment variables for configuration. When deploying to Vercel:
-
Set up the following environment variables in your Vercel project settings:
OPENAI_API_KEY: Your OpenAI API keySUPABASE_URL: Your Supabase URLSUPABASE_ANON_KEY: Your Supabase anonymous key
-
The
vercel.jsonfile is configured to automatically use these environment variables during the build process.
For local development:
-
Create a
.envfile in the project root with the following variables:OPENAI_API_KEY=your_api_key_here SUPABASE_URL=your_supabase_url SUPABASE_ANON_KEY=your_supabase_anon_key -
Run the app using:
flutter run -d chrome
You can also use --dart-define to inject environment variables at build time:
flutter run -d chrome --dart-define=OPENAI_API_KEY=your_api_key_hereFor production builds:
flutter build web --release --dart-define=OPENAI_API_KEY=your_api_key_here