-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
17 changed files
with
195 additions
and
24 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
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
2 changes: 0 additions & 2 deletions
2
lib/04_album_photo/presentation/photo_detail/photo_detail_screen.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
1 change: 0 additions & 1 deletion
1
lib/04_album_photo/presentation/photo_list/photo_list_screen.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
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
12 changes: 12 additions & 0 deletions
12
lib/09_use_case/domain/use_case/get_photos_top3_use_case.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,12 @@ | ||
import '../model/photo.dart'; | ||
import '../repository/photo_repository.dart'; | ||
|
||
class GetPhotosTop3UseCase { | ||
final PhotoRepository _photoRepository; | ||
|
||
GetPhotosTop3UseCase(this._photoRepository); | ||
|
||
Future<List<Photo>> execute(String query) async { | ||
return (await _photoRepository.getPhotos(query)).take(3).toList(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
lib/09_use_case/domain/use_case/get_photos_top5_use_case.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,12 @@ | ||
import '../model/photo.dart'; | ||
import '../repository/photo_repository.dart'; | ||
|
||
class GetPhotosTop5UseCase { | ||
final PhotoRepository _photoRepository; | ||
|
||
GetPhotosTop5UseCase(this._photoRepository); | ||
|
||
Future<List<Photo>> execute(String query) async { | ||
return (await _photoRepository.getPhotos(query)).take(5).toList(); | ||
} | ||
} |
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,12 +1,23 @@ | ||
import 'package:learn_flutter_together/09_use_case/domain/use_case/get_photos_top3_use_case.dart'; | ||
import 'package:learn_flutter_together/09_use_case/domain/use_case/get_photos_top5_use_case.dart'; | ||
|
||
import '../model/photo.dart'; | ||
import '../repository/photo_repository.dart'; | ||
|
||
class GetPhotosUseCase { | ||
final PhotoRepository _photoRepository; | ||
final GetPhotosTop3UseCase _getPhotosTop3UseCase; | ||
final GetPhotosTop5UseCase _getPhotosTop5UseCase; | ||
|
||
GetPhotosUseCase(this._photoRepository); | ||
const GetPhotosUseCase({ | ||
required GetPhotosTop3UseCase getPhotosTop3UseCase, | ||
required GetPhotosTop5UseCase getPhotosTop5UseCase, | ||
}) : _getPhotosTop3UseCase = getPhotosTop3UseCase, | ||
_getPhotosTop5UseCase = getPhotosTop5UseCase; | ||
|
||
Future<List<Photo>> execute(String query) async { | ||
return (await _photoRepository.getPhotos(query)).take(3).toList(); | ||
if (DateTime.now().minute.isEven) { | ||
return _getPhotosTop3UseCase.execute(query); | ||
} else { | ||
return _getPhotosTop5UseCase.execute(query); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
lib/09_use_case/domain/use_case/search_list_use_cases.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,16 @@ | ||
import 'package:learn_flutter_together/09_use_case/domain/use_case/get_photos_top3_use_case.dart'; | ||
|
||
import 'get_photos_top5_use_case.dart'; | ||
import 'get_photos_use_case.dart'; | ||
|
||
class SearchListUseCases { | ||
final GetPhotosTop3UseCase getPhotosTop3UseCase; | ||
final GetPhotosTop5UseCase getPhotosTop5UseCase; | ||
final GetPhotosUseCase getPhotosUseCase; | ||
|
||
const SearchListUseCases({ | ||
required this.getPhotosTop3UseCase, | ||
required this.getPhotosTop5UseCase, | ||
required this.getPhotosUseCase, | ||
}); | ||
} |
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
2 changes: 1 addition & 1 deletion
2
lib/09_use_case/presentation/search_list/search_list_view_model.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
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,84 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
import 'model/photo.dart'; | ||
|
||
void main() { | ||
runApp(const MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({super.key}); | ||
|
||
// This widget is the root of your application. | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Demo', | ||
theme: ThemeData( | ||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | ||
useMaterial3: true, | ||
), | ||
home: const ImageSearchApp(), | ||
); | ||
} | ||
} | ||
|
||
class ImageSearchApp extends StatefulWidget { | ||
const ImageSearchApp({super.key}); | ||
|
||
@override | ||
State<ImageSearchApp> createState() => _ImageSearchAppState(); | ||
} | ||
|
||
class _ImageSearchAppState extends State<ImageSearchApp> { | ||
final _url = | ||
'https://pixabay.com/api/?key=10711147-dc41758b93b263957026bdadb&q=yellow+flowers&image_type=photo'; | ||
|
||
Future<List<Photo>> getPhotos(String query) async { | ||
final response = await http.get(Uri.parse(_url)); | ||
final List jsonList = jsonDecode(response.body)['hits']; | ||
return jsonList.map((e) => Photo.fromJson(e)).toList(); | ||
} | ||
|
||
final controller = TextEditingController(); | ||
|
||
@override | ||
void dispose() { | ||
controller.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('이미지 검색'), | ||
), | ||
body: Column( | ||
children: [ | ||
TextField( | ||
controller: controller, | ||
), | ||
ElevatedButton( | ||
onPressed: () { | ||
setState(() {}); | ||
}, | ||
child: const Text('검색'), | ||
), | ||
Expanded( | ||
child: FutureBuilder<List<Photo>>( | ||
future: getPhotos(controller.text), | ||
builder: (context, snapshot) { | ||
return ListView.builder( | ||
itemBuilder: (BuildContext context, int index) {}, | ||
); | ||
}), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
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,15 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'photo.freezed.dart'; | ||
|
||
part 'photo.g.dart'; | ||
|
||
@freezed | ||
class Photo with _$Photo { | ||
const factory Photo({ | ||
required String tags, | ||
@JsonKey(name: 'previewURL') required String imageUrl, | ||
}) = _Photo; | ||
|
||
factory Photo.fromJson(Map<String, Object?> json) => _$PhotoFromJson(json); | ||
} |
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