-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Day 4 #16
Open
DVis23
wants to merge
7
commits into
surfstudio:main
Choose a base branch
from
DVis23:Day-4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Day 4 #16
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
68bfbbb
Initial commit
DVis23 256002f
Second commit
DVis23 0fac613
... + Equatable + Elementary
DVis23 3c92307
Update README.md
DVis23 097945d
Update README.md
DVis23 d7b16c0
... + Elementary for PhotoView Pages + backend (images download/uplo…
DVis23 73d547c
Merge remote-tracking branch 'origin/main'
DVis23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# surf_flutter_summer_school_24 | ||
|
||
Шаблонный репозиторий для Surf Flutter Summer School '24 | ||
![Screenshot_20240724_223550](https://github.com/user-attachments/assets/fa94c98e-a9d6-411a-9a06-b9aaa0d099ff) | ||
![Screenshot_20240724_223810](https://github.com/user-attachments/assets/5a15f69d-4c85-420f-91f8-6defd15e5310) | ||
![Screenshot_20240724_223903](https://github.com/user-attachments/assets/609be02a-7446-43c5-b17c-c344bc3f26ec) | ||
![Screenshot_20240724_223949](https://github.com/user-attachments/assets/da60db58-081d-4d58-b473-c19fa2904b64) | ||
![Screenshot_20240724_224044](https://github.com/user-attachments/assets/49cc926d-6b77-404a-8b93-fcb94aeb4898) | ||
![Screenshot_20240724_224117](https://github.com/user-attachments/assets/d52cc536-1ffa-4585-8b55-bca0daeaa60c) | ||
![Screenshot_20240724_224314](https://github.com/user-attachments/assets/6f00962d-2a56-4c8c-b696-20c0c2901f2a) | ||
![Screenshot_20240724_224235](https://github.com/user-attachments/assets/e71b2ff2-3bb9-4f86-a861-e9bd69bfec5c) | ||
![Screenshot_20240724_224210](https://github.com/user-attachments/assets/4c673ea4-a26d-4f1b-af6d-24fa7c085487) |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:http/http.dart' as http; | ||
|
||
import '../domain/models/photo_entity.dart'; | ||
|
||
Future<List<PhotoEntity>> downloadImageFromYandexCloud() async { | ||
const token = 'y0_AgAAAABZVuavAADLWwAAAAELdHsRAAAWFyiqDOJE_LPjdaheqhXn63NSWA'; | ||
|
||
final uri = Uri.https( | ||
'cloud-api.yandex.net', | ||
'v1/disk/resources', | ||
{ | ||
"path": '/', | ||
}, | ||
); | ||
|
||
final response = await http.get( | ||
uri, | ||
headers: { | ||
HttpHeaders.authorizationHeader: 'OAuth $token', | ||
}, | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
final body = response.body; | ||
final json = jsonDecode(body) as Map<String, dynamic>; | ||
final items = json['_embedded']['items'] as List<dynamic>; | ||
|
||
return items.where((item) { | ||
final url = item['file'] as String?; | ||
return url != null && url.isNotEmpty; | ||
}).map((item) { | ||
final id = item['name'] as String; | ||
final url = item['file'] as String; | ||
final createAt = DateTime.tryParse(item['created']) ?? null; | ||
return PhotoEntity( | ||
id: id, | ||
url: url, | ||
createAt: createAt, | ||
); | ||
}).toList(); | ||
} else { | ||
throw Exception('Ошибка получения фотографий с Яндекс.Диска'); | ||
} | ||
} |
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,16 @@ | ||
import '../domain/i_photo_repository.dart'; | ||
import '../domain/models/photo_entity.dart'; | ||
|
||
|
||
import 'dowload_image_to_cload.dart'; | ||
|
||
class PhotoRepository implements IPhotoRepository { | ||
|
||
@override | ||
Future<List<PhotoEntity>> getPhotos() async { | ||
final photos = await downloadImageFromYandexCloud(); | ||
return photos; | ||
} | ||
|
||
} | ||
|
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,36 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
Future<void> uploadImageToYandexCloud(String imagePath) async { | ||
const token = 'y0_AgAAAABZVuavAADLWwAAAAELdHsRAAAWFyiqDOJE_LPjdaheqhXn63NSWA'; | ||
|
||
final uri = Uri.https( | ||
'cloud-api.yandex.net', | ||
'v1/disk/resources/upload', | ||
{ | ||
"path": imagePath.split('/').last, | ||
}, | ||
); | ||
|
||
final response = await http.get( | ||
uri, | ||
headers: { | ||
HttpHeaders.authorizationHeader: 'OAuth $token', | ||
}, | ||
); | ||
|
||
final body = response.body; | ||
final json = jsonDecode(body); | ||
json as Map<String, dynamic>; | ||
final linkToUpload = json['href'] as String; | ||
|
||
final dio = Dio(); | ||
final file = File(imagePath); | ||
final formData = FormData.fromMap({ | ||
'file': await MultipartFile.fromFile(file.path), | ||
}); | ||
await dio.put(linkToUpload, data: formData); | ||
} |
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,5 @@ | ||
import 'models/photo_entity.dart'; | ||
|
||
abstract interface class IPhotoRepository { | ||
Future<List<PhotoEntity>> getPhotos(); | ||
} |
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,20 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
final class PhotoEntity extends Equatable { | ||
final String id; | ||
final String url; | ||
final DateTime? createAt; | ||
|
||
const PhotoEntity({ | ||
required this.id, | ||
required this.url, | ||
this.createAt, | ||
}); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
id, | ||
url, | ||
createAt, | ||
]; | ||
} |
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,22 @@ | ||
import 'package:surf_flutter_summer_school_24/src/storage/theme/theme_storage.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ThemeRepository { | ||
final ThemeStorage _themeStorage; | ||
|
||
ThemeRepository({ | ||
required ThemeStorage themeStorage, | ||
}) : _themeStorage = themeStorage; | ||
|
||
Future<void> setThemeMode( | ||
ThemeMode newThemeMode, | ||
) async { | ||
await _themeStorage.saveThemeMode( | ||
mode: newThemeMode, | ||
); | ||
} | ||
|
||
ThemeMode? getThemeMode() { | ||
return _themeStorage.getThemeMode(); | ||
} | ||
} |
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,27 @@ | ||
import 'package:flutter/material.dart'; | ||
import '../domain/theme_controller.dart'; | ||
|
||
class ThemeInherited extends InheritedWidget { | ||
const ThemeInherited({ | ||
super.key, | ||
required this.themeController, | ||
required super.child, | ||
}); | ||
|
||
final ThemeController themeController; | ||
|
||
static ThemeController? maybeOf(BuildContext context) { | ||
return context | ||
.dependOnInheritedWidgetOfExactType<ThemeInherited>() | ||
?.themeController; | ||
} | ||
|
||
static ThemeController of(BuildContext context) { | ||
final ThemeController? result = maybeOf(context); | ||
assert(result != null, 'No MyThemeInherited found in context'); | ||
return result!; | ||
} | ||
|
||
@override | ||
bool updateShouldNotify(ThemeInherited oldWidget) => false; | ||
} |
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,30 @@ | ||
import 'package:surf_flutter_summer_school_24/src/feature/theme/data/theme_repository.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ThemeController { | ||
final ThemeRepository _themeRepository; | ||
|
||
ThemeController({ | ||
required ThemeRepository themeRepository, | ||
}) : _themeRepository = themeRepository; | ||
|
||
late final ValueNotifier<ThemeMode> _themeMode = ValueNotifier<ThemeMode>( | ||
_themeRepository.getThemeMode() ?? ThemeMode.system, | ||
); | ||
|
||
ValueListenable<ThemeMode> get themeMode => _themeMode; | ||
|
||
Future<void> setThemeMode(ThemeMode newThemeMode) async { | ||
if (newThemeMode == _themeMode.value) return; | ||
await _themeRepository.setThemeMode(newThemeMode); | ||
_themeMode.value = newThemeMode; | ||
} | ||
|
||
Future<void> switchThemeMode() async { | ||
final newThemeMode = | ||
_themeMode.value != ThemeMode.light ? ThemeMode.light : ThemeMode.dark; | ||
await _themeRepository.setThemeMode(newThemeMode); | ||
_themeMode.value = newThemeMode; | ||
} | ||
} |
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,37 @@ | ||
import 'package:surf_flutter_summer_school_24/src/feature/theme/di/theme_inherited.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
typedef ThemeWidgetBuilder = Widget Function( | ||
BuildContext context, | ||
ThemeMode themeMode, | ||
); | ||
|
||
class ThemeBuilder extends StatefulWidget { | ||
const ThemeBuilder({ | ||
required this.builder, | ||
super.key, | ||
}); | ||
|
||
final ThemeWidgetBuilder builder; | ||
|
||
@override | ||
State<ThemeBuilder> createState() => _ThemeBuilderState(); | ||
} | ||
|
||
class _ThemeBuilderState extends State<ThemeBuilder> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return ValueListenableBuilder<ThemeMode>( | ||
valueListenable: ThemeInherited.of(context).themeMode, | ||
builder: ( | ||
builderContext, | ||
themeMode, | ||
_, | ||
) => | ||
widget.builder( | ||
builderContext, | ||
themeMode, | ||
), | ||
); | ||
} | ||
} |
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,50 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:surf_flutter_summer_school_24/src/feature/theme/data/theme_repository.dart'; | ||
import 'package:surf_flutter_summer_school_24/src/feature/theme/di/theme_inherited.dart'; | ||
import 'package:surf_flutter_summer_school_24/src/feature/theme/domain/theme_controller.dart'; | ||
import 'package:surf_flutter_summer_school_24/src/feature/theme/ui/theme_builder.dart'; | ||
import 'package:surf_flutter_summer_school_24/src/pages/gallery/gallery_widget.dart'; | ||
import 'package:surf_flutter_summer_school_24/src/storage/theme/theme_storage.dart'; | ||
import 'package:surf_flutter_summer_school_24/src/uikit/theme/theme_data.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
final prefs = await SharedPreferences.getInstance(); | ||
final themeStorage = ThemeStorage( | ||
prefs: prefs, | ||
); | ||
final themeRepository = ThemeRepository( | ||
themeStorage: themeStorage, | ||
); | ||
final themeController = ThemeController( | ||
themeRepository: themeRepository, | ||
); | ||
runApp(MainApp( | ||
themeController: themeController, | ||
)); | ||
} | ||
|
||
class MainApp extends StatelessWidget { | ||
final ThemeController themeController; | ||
|
||
const MainApp({super.key, required this.themeController,}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ThemeInherited( | ||
themeController: themeController, | ||
child: ThemeBuilder( | ||
builder: (_, themeMode) { | ||
return MaterialApp( | ||
theme: AppThemeData.lightTheme, | ||
darkTheme: AppThemeData.darkTheme, | ||
themeMode: themeMode, | ||
home: const GalleryWidget() | ||
); | ||
}, | ||
) | ||
); | ||
} | ||
} | ||
|
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,17 @@ | ||
import 'package:elementary/elementary.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../feature/photos/domain/i_photo_repository.dart'; | ||
import '../../feature/photos/domain/models/photo_entity.dart'; | ||
|
||
class GalleryModel extends ElementaryModel { | ||
final IPhotoRepository photoRepository; | ||
final ValueNotifier<List<PhotoEntity>> images = ValueNotifier([]); | ||
|
||
GalleryModel(this.photoRepository); | ||
|
||
Future<void> fetchPhotos() async { | ||
final photos = await photoRepository.getPhotos(); | ||
images.value = photos; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Эта штука тоже должна быть в репозитории