Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
424Nkita-Csharsfta4 authored Feb 23, 2024
1 parent 564f4b6 commit a3db8bd
Show file tree
Hide file tree
Showing 15 changed files with 589 additions and 172 deletions.
2 changes: 1 addition & 1 deletion lib/course/local_storage/local_storage_curse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ class LocalStorageService {
void saveSelectedCourse(Course selectedCourse) {
// TODO: Сохранение выбранного курса в локальное хранилище
// Это место для логики сохранения курса в локальное хранилище
print('Course saved: ${selectedCourse.name}');
print('Курсы сохранены: ${selectedCourse.name}');
}
}
4 changes: 2 additions & 2 deletions lib/course/widgets/custom_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class CustomCard extends StatelessWidget {
Container(
decoration: BoxDecoration(
color: course.isFree
? Colors.green
: const Color.fromARGB(255, 243, 33, 33),
? const Color.fromARGB(193, 128, 249, 132)
: const Color.fromARGB(121, 255, 88, 88),
borderRadius: BorderRadius.circular(6),
),
padding: const EdgeInsets.symmetric(
Expand Down
10 changes: 1 addition & 9 deletions lib/json/course.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
"lessons": 16,
"tests": 14,
"documentation": "https://example.com/flutter-docs"
},
{
"id": 2,
"imageUrl": "https://example.com/image2.jpg",
"name": "Web Development",
"description": "Complete guide to modern web development",
"lessons": 30,
"tests": 10,
"documentation": "https://example.com/web-dev-docs"
}

]
36 changes: 17 additions & 19 deletions lib/main.dart
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(),
);
}
}
25 changes: 25 additions & 0 deletions lib/router/router.dart
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(),
),
],
);
}
29 changes: 29 additions & 0 deletions lib/screens/auntification/block/login_state_block.dart
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();
}
}
}
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 lib/screens/auntification/login/model/login_with_image.dart
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 lib/screens/auntification/login/model/login_without_image.dart
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);
}
}
}
Loading

0 comments on commit a3db8bd

Please sign in to comment.