Skip to content
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 3 #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 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_224015](https://github.com/user-attachments/assets/46655c2a-39c3-4d94-8a27-1cad28752049)
![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 added fonts/Magnolia.ttf
Binary file not shown.
20 changes: 0 additions & 20 deletions lib/main.dart

This file was deleted.

5 changes: 5 additions & 0 deletions lib/src/feature/photos/data/i_photo_repository.dart
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();
}
130 changes: 130 additions & 0 deletions lib/src/feature/photos/data/mock_photo_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import 'package:surf_flutter_summer_school_24/src/feature/photos/data/i_photo_repository.dart';
import 'package:surf_flutter_summer_school_24/src/models/photo_entity.dart';


class MockPhotoRepository implements IPhotoRepository {
@override
Future<List<PhotoEntity>> getPhotos() async{
return [
const PhotoEntity(
id: '1',
url: 'https://sun9-67.userapi.com/impg/tX4OvfRLP0qjy8pX-D7WGIrPp6tU9Kk5OQErBw/O7cfSBKIhps.jpg?size=1199x1199&quality=95&sign=032b69843ac686317904906820bf4020&type=album'
),
const PhotoEntity(
id: '2',
url: 'https://sun9-70.userapi.com/impg/5y5vwIq2-aaxiyscdm9XWy3iOw-KDQUPbWoidg/-J_O_1Pnx9Q.jpg?size=1024x1280&quality=96&sign=285af90845367d97da75d3dbceabbea0&type=album'
),
const PhotoEntity(
id: '3',
url: 'https://sun9-66.userapi.com/impg/c855428/v855428659/1df047/63VkypHBeZo.jpg?size=604x377&quality=96&sign=84e35c2c415bcf6603d8c81269bcfec4&type=album'
),
const PhotoEntity(
id: '4',
url: 'https://sun9-55.userapi.com/impg/mDIc6RPZmIznA9Uip0tKXeep7gQg5ot0XUUaVw/OyDLqBzPL0A.jpg?size=1024x1280&quality=96&sign=a38727bf7d11a4b1811446972e048f9e&type=album'
),
const PhotoEntity(
id: '5',
url: 'https://sun9-38.userapi.com/impg/mtqQmWCnxwMDRjqVGEiczyfZ0CqSu7G7e1BpMg/JOfRS5xYG_w.jpg?size=884x884&quality=96&sign=d972f22e5d4b8d82c82323b81655e86e&type=album'
),
const PhotoEntity(
id: '6',
url: 'https://sun9-25.userapi.com/impg/U1xodQh60uHV1H75doPQtI9lHR-ps4y7pQ7KTQ/vsRSDAx2Ma8.jpg?size=639x641&quality=96&sign=975c4c8ee9bd5e4c3976f211ef239c98&type=album'
),
const PhotoEntity(
id: '7',
url: 'https://sun9-24.userapi.com/impg/UVP9-Kst1oeGJvfFz6cOgCFRgMacoQrqYeqdZA/s4SRxgafGxk.jpg?size=637x634&quality=96&sign=80155bf77dc4385ccf467379490b1da4&type=album'
),
const PhotoEntity(
id: '8',
url: 'https://sun9-30.userapi.com/impg/MO4GiY_8B_f3ep-8NusBQWAZOy-QJVTHWyZ2Cw/EJRz0qfPmJE.jpg?size=564x564&quality=96&sign=ef87156b2be6159ab306e12152df3d29&type=album'
),
const PhotoEntity(
id: '9',
url: 'https://sun9-67.userapi.com/impg/tX4OvfRLP0qjy8pX-D7WGIrPp6tU9Kk5OQErBw/O7cfSBKIhps.jpg?size=1199x1199&quality=95&sign=032b69843ac686317904906820bf4020&type=album'
),
const PhotoEntity(
id: '10',
url: 'https://sun9-40.userapi.com/impf/c846017/v846017039/c4d2a/_QCZsc09OYE.jpg?size=540x530&quality=96&sign=733f462520a192a9bbf5b716f00c2a2f&type=album'
),
const PhotoEntity(
id: '11',
url: 'https://sun9-67.userapi.com/impg/tX4OvfRLP0qjy8pX-D7WGIrPp6tU9Kk5OQErBw/O7cfSBKIhps.jpg?size=1199x1199&quality=95&sign=032b69843ac686317904906820bf4020&type=album'
),
const PhotoEntity(
id: '12',
url: 'https://sun9-70.userapi.com/impg/5y5vwIq2-aaxiyscdm9XWy3iOw-KDQUPbWoidg/-J_O_1Pnx9Q.jpg?size=1024x1280&quality=96&sign=285af90845367d97da75d3dbceabbea0&type=album'
),
const PhotoEntity(
id: '13',
url: 'https://sun9-66.userapi.com/impg/c855428/v855428659/1df047/63VkypHBeZo.jpg?size=604x377&quality=96&sign=84e35c2c415bcf6603d8c81269bcfec4&type=album'
),
const PhotoEntity(
id: '14',
url: 'https://sun9-55.userapi.com/impg/mDIc6RPZmIznA9Uip0tKXeep7gQg5ot0XUUaVw/OyDLqBzPL0A.jpg?size=1024x1280&quality=96&sign=a38727bf7d11a4b1811446972e048f9e&type=album'
),
const PhotoEntity(
id: '15',
url: 'https://sun9-38.userapi.com/impg/mtqQmWCnxwMDRjqVGEiczyfZ0CqSu7G7e1BpMg/JOfRS5xYG_w.jpg?size=884x884&quality=96&sign=d972f22e5d4b8d82c82323b81655e86e&type=album'
),
const PhotoEntity(
id: '16',
url: 'https://sun9-25.userapi.com/impg/U1xodQh60uHV1H75doPQtI9lHR-ps4y7pQ7KTQ/vsRSDAx2Ma8.jpg?size=639x641&quality=96&sign=975c4c8ee9bd5e4c3976f211ef239c98&type=album'
),
const PhotoEntity(
id: '17',
url: 'https://sun9-24.userapi.com/impg/UVP9-Kst1oeGJvfFz6cOgCFRgMacoQrqYeqdZA/s4SRxgafGxk.jpg?size=637x634&quality=96&sign=80155bf77dc4385ccf467379490b1da4&type=album'
),
const PhotoEntity(
id: '18',
url: 'https://sun9-30.userapi.com/impg/MO4GiY_8B_f3ep-8NusBQWAZOy-QJVTHWyZ2Cw/EJRz0qfPmJE.jpg?size=564x564&quality=96&sign=ef87156b2be6159ab306e12152df3d29&type=album'
),
const PhotoEntity(
id: '19',
url: 'https://sun9-67.userapi.com/impg/tX4OvfRLP0qjy8pX-D7WGIrPp6tU9Kk5OQErBw/O7cfSBKIhps.jpg?size=1199x1199&quality=95&sign=032b69843ac686317904906820bf4020&type=album'
),
const PhotoEntity(
id: '20',
url: 'https://sun9-40.userapi.com/impf/c846017/v846017039/c4d2a/_QCZsc09OYE.jpg?size=540x530&quality=96&sign=733f462520a192a9bbf5b716f00c2a2f&type=album'
),const PhotoEntity(
id: '21',
url: 'https://sun9-67.userapi.com/impg/tX4OvfRLP0qjy8pX-D7WGIrPp6tU9Kk5OQErBw/O7cfSBKIhps.jpg?size=1199x1199&quality=95&sign=032b69843ac686317904906820bf4020&type=album'
),
const PhotoEntity(
id: '22',
url: 'https://sun9-70.userapi.com/impg/5y5vwIq2-aaxiyscdm9XWy3iOw-KDQUPbWoidg/-J_O_1Pnx9Q.jpg?size=1024x1280&quality=96&sign=285af90845367d97da75d3dbceabbea0&type=album'
),
const PhotoEntity(
id: '23',
url: 'https://sun9-66.userapi.com/impg/c855428/v855428659/1df047/63VkypHBeZo.jpg?size=604x377&quality=96&sign=84e35c2c415bcf6603d8c81269bcfec4&type=album'
),
const PhotoEntity(
id: '24',
url: 'https://sun9-55.userapi.com/impg/mDIc6RPZmIznA9Uip0tKXeep7gQg5ot0XUUaVw/OyDLqBzPL0A.jpg?size=1024x1280&quality=96&sign=a38727bf7d11a4b1811446972e048f9e&type=album'
),
const PhotoEntity(
id: '25',
url: 'https://sun9-38.userapi.com/impg/mtqQmWCnxwMDRjqVGEiczyfZ0CqSu7G7e1BpMg/JOfRS5xYG_w.jpg?size=884x884&quality=96&sign=d972f22e5d4b8d82c82323b81655e86e&type=album'
),
const PhotoEntity(
id: '26',
url: 'https://sun9-25.userapi.com/impg/U1xodQh60uHV1H75doPQtI9lHR-ps4y7pQ7KTQ/vsRSDAx2Ma8.jpg?size=639x641&quality=96&sign=975c4c8ee9bd5e4c3976f211ef239c98&type=album'
),
const PhotoEntity(
id: '27',
url: 'https://sun9-24.userapi.com/impg/UVP9-Kst1oeGJvfFz6cOgCFRgMacoQrqYeqdZA/s4SRxgafGxk.jpg?size=637x634&quality=96&sign=80155bf77dc4385ccf467379490b1da4&type=album'
),
const PhotoEntity(
id: '28',
url: 'https://sun9-30.userapi.com/impg/MO4GiY_8B_f3ep-8NusBQWAZOy-QJVTHWyZ2Cw/EJRz0qfPmJE.jpg?size=564x564&quality=96&sign=ef87156b2be6159ab306e12152df3d29&type=album'
),
const PhotoEntity(
id: '29',
url: 'https://sun9-67.userapi.com/impg/tX4OvfRLP0qjy8pX-D7WGIrPp6tU9Kk5OQErBw/O7cfSBKIhps.jpg?size=1199x1199&quality=95&sign=032b69843ac686317904906820bf4020&type=album'
),
const PhotoEntity(
id: '30',
url: 'https://sun9-40.userapi.com/impf/c846017/v846017039/c4d2a/_QCZsc09OYE.jpg?size=540x530&quality=96&sign=733f462520a192a9bbf5b716f00c2a2f&type=album'
),
];
}
}
22 changes: 22 additions & 0 deletions lib/src/feature/theme/data/theme_repository.dart
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();
}
}
27 changes: 27 additions & 0 deletions lib/src/feature/theme/di/theme_inherited.dart
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;
}
30 changes: 30 additions & 0 deletions lib/src/feature/theme/domain/theme_controller.dart
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;
}
}
37 changes: 37 additions & 0 deletions lib/src/feature/theme/ui/theme_builder.dart
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,
),
);
}
}
50 changes: 50 additions & 0 deletions lib/src/main.dart
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()
);
},
)
);
}
}

20 changes: 20 additions & 0 deletions lib/src/models/photo_entity.dart
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,
];
}
16 changes: 16 additions & 0 deletions lib/src/pages/gallery/gallery_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:elementary/elementary.dart';
import 'package:flutter/material.dart';
import '../../feature/photos/data/i_photo_repository.dart';
import '../../models/photo_entity.dart';

class GalleryModel extends ElementaryModel {
final IPhotoRepository photoRepository;
final ValueNotifier<List<PhotoEntity>> images = ValueNotifier([]); // Используем ValueNotifier

GalleryModel(this.photoRepository);

Future<void> fetchPhotos() async {
final photos = await photoRepository.getPhotos();
images.value = photos; // Обновляем ValueNotifier
}
}
Loading