-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
564f4b6
commit a3db8bd
Showing
15 changed files
with
589 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:firebase_core/firebase_core.dart'; | ||
import 'package:skillwave/bloc/onbourding_bloc.dart'; | ||
import 'package:skillwave/course/screens/dashboard_screen.dart'; | ||
import 'package:skillwave/screens/auntification/login/login.dart'; | ||
import 'package:skillwave/screens/auntification/sign/sign.dart'; | ||
import 'package:skillwave/screens/auntification/block/login_state_block.dart'; | ||
import 'package:skillwave/screens/onbourding/onboarding_screen.dart'; | ||
import 'package:skillwave/screens/profile/profile.dart'; | ||
// import 'package:skillwave/screens/auntification/sign/sign.dart'; | ||
// ignore: unused_import, depend_on_referenced_packages | ||
import 'package:supabase/supabase.dart'; | ||
import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
await Firebase.initializeApp( | ||
options: const FirebaseOptions( | ||
apiKey: 'AIzaSyC-AcRDGJ775rr7MaOiL2IgwtSZ0vh7_jA', | ||
projectId: 'auntefication-98ff3', | ||
appId: '1:211196806595:android:750c99a1e160a6965ca976', | ||
messagingSenderId: '', | ||
), | ||
await Supabase.initialize( | ||
url: 'https://xywozykuxyqkubprtzql.supabase.co', | ||
anonKey: | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh5d296eWt1eHlxa3VicHJ0enFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDg1MDY3NzUsImV4cCI6MjAyNDA4Mjc3NX0.pZHIMs4Jzm-h4dPzA8jqqiqZPKhOFKUCRoMljmKM54g', | ||
); | ||
|
||
runApp(const MyApp()); | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
MyApp({super.key}); | ||
final RegistrationStateManager registrationStateManager = | ||
RegistrationStateManager(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
home: DashboardScreen(), | ||
return MaterialApp( | ||
// theme: ThemeData.light(), | ||
darkTheme: ThemeData.dark(), | ||
home: const Onboarding(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:skillwave/course/screens/dashboard_screen.dart'; | ||
import 'package:skillwave/screens/profile/profile.dart'; | ||
import 'package:skillwave/screens/profile/update_profile/update_profile.dart'; | ||
|
||
class AppRouter { | ||
static final router = GoRouter( | ||
initialLocation: '/dashboard', | ||
routes: [ | ||
GoRoute( | ||
path: '/dashboard', | ||
builder: (context, state) => const DashboardScreen(), | ||
), | ||
GoRoute( | ||
path: '/profile', | ||
builder: (context, state) => ProfileScreen(), | ||
), | ||
GoRoute( | ||
path: '/update_profile', | ||
builder: (context, state) => const UpdateProfileScreen(), | ||
), | ||
], | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'dart:io'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:skillwave/course/screens/dashboard_screen.dart'; | ||
import 'package:skillwave/screens/auntification/login/interface/registration_strategy.dart'; | ||
|
||
class RegistrationStateManager extends ChangeNotifier { | ||
bool _registrationInProgress = false; | ||
bool get registrationInProgress => _registrationInProgress; | ||
|
||
void startRegistration(BuildContext context, String name, String email, | ||
String password, File? image, RegistrationStrategy strategy) async { | ||
_registrationInProgress = true; | ||
notifyListeners(); | ||
|
||
try { | ||
await strategy.register(context, name, email, password, image); | ||
} catch (e) { | ||
print("Error during registration: $e"); | ||
// ignore: use_build_context_synchronously | ||
Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute(builder: (context) => const DashboardScreen()), | ||
); | ||
} finally { | ||
_registrationInProgress = false; | ||
notifyListeners(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
lib/screens/auntification/login/interface/registration_strategy.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
/// Интерфейс для стратегии регистрации | ||
abstract class RegistrationStrategy { | ||
Future<void> register(BuildContext context, String name, String email, | ||
String password, File? image); | ||
} |
69 changes: 69 additions & 0 deletions
69
lib/screens/auntification/login/model/login_with_image.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// Патерн стратегия | ||
import 'dart:convert'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:skillwave/course/screens/dashboard_screen.dart'; | ||
import 'package:skillwave/screens/auntification/login/interface/registration_strategy.dart'; | ||
import 'dart:io'; | ||
import 'package:http/http.dart' as http; | ||
|
||
///Стратегия для регистрации с изображением | ||
class RegistrationWithImage implements RegistrationStrategy { | ||
@override | ||
Future<void> register(BuildContext context, String name, String email, | ||
String password, File? image) async { | ||
if (image != null) { | ||
File imageFile = File(image.path); | ||
List<int> imageBytes = await imageFile.readAsBytes(); | ||
String base64Image = base64Encode(imageBytes); | ||
|
||
try { | ||
final response = await http.post( | ||
Uri.parse('https://xywozykuxyqkubprtzql.supabase.co'), | ||
headers: <String, String>{ | ||
'Content-Type': 'application/json', | ||
'apikey': | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh5d296eWt1eHlxa3VicHJ0enFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDg1MDY3NzUsImV4cCI6MjAyNDA4Mjc3NX0.pZHIMs4Jzm-h4dPzA8jqqiqZPKhOFKUCRoMljmKM54g', | ||
}, | ||
body: jsonEncode(<String, String>{ | ||
'name': name, | ||
'email': email, | ||
'password': password, | ||
}), | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
final userData = jsonDecode(response.body); | ||
|
||
final imageResponse = await http.post( | ||
Uri.parse('https://xywozykuxyqkubprtzql.supabase.co'), | ||
headers: <String, String>{ | ||
'Content-Type': 'application/json', | ||
'apikey': | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh5d296eWt1eHlxa3VicHJ0enFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDg1MDY3NzUsImV4cCI6MjAyNDA4Mjc3NX0.pZHIMs4Jzm-h4dPzA8jqqiqZPKhOFKUCRoMljmKM54g', | ||
}, | ||
body: jsonEncode(<String, dynamic>{ | ||
'user_id': userData['id'], | ||
'image_data': base64Image, | ||
}), | ||
); | ||
|
||
if (imageResponse.statusCode == 200) { | ||
print('Image uploaded successfully'); | ||
} else { | ||
print('Failed to upload image'); | ||
} | ||
|
||
// ignore: use_build_context_synchronously | ||
Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute(builder: (context) => const DashboardScreen()), | ||
); | ||
} else { | ||
print('Failed to register user: ${response.body}'); | ||
} | ||
} catch (e) { | ||
print(e); | ||
} | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
lib/screens/auntification/login/model/login_without_image.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/// Патерн стратегия | ||
import 'dart:convert'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:skillwave/course/screens/dashboard_screen.dart'; | ||
import 'package:skillwave/screens/auntification/login/interface/registration_strategy.dart'; | ||
import 'dart:io'; | ||
import 'package:http/http.dart' as http; | ||
|
||
///Стратегия для регистрации без изображения | ||
class RegistrationWithoutImage implements RegistrationStrategy { | ||
@override | ||
Future<void> register(BuildContext context, String name, String email, | ||
String password, File? image) async { | ||
try { | ||
final response = await http.post( | ||
Uri.parse('https://xywozykuxyqkubprtzql.supabase.co'), | ||
headers: <String, String>{ | ||
'Content-Type': 'application/json', | ||
'apikey': | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh5d296eWt1eHlxa3VicHJ0enFsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDg1MDY3NzUsImV4cCI6MjAyNDA4Mjc3NX0.pZHIMs4Jzm-h4dPzA8jqqiqZPKhOFKUCRoMljmKM54g', | ||
}, | ||
body: jsonEncode(<String, String>{ | ||
'name': name, | ||
'email': email, | ||
'password': password, | ||
}), | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
// ignore: use_build_context_synchronously | ||
Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute(builder: (context) => const DashboardScreen()), | ||
); | ||
} else { | ||
print('Failed to register user: ${response.body}'); | ||
} | ||
} catch (e) { | ||
print(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.