22 changed files with 206 additions and 314 deletions
-
BINassets/images/loading.png
-
2lib/core/constants/my_constants.dart
-
23lib/core/middlewares/my_middlewares.dart
-
12lib/core/routers/my_routes.dart
-
50lib/core/widgets/animations/rotation_anim.dart
-
59lib/features/download/data/datasource/download_datasource.dart
-
16lib/features/download/data/repository_impl/download_repository_impl.dart
-
1lib/features/download/domain/repository/download_repository.dart
-
4lib/features/download/domain/usecases/get_images_usecase.dart
-
4lib/features/download/domain/usecases/loading_stream_usecase.dart
-
31lib/features/download/presentation/bloc/download_bloc.dart
-
1lib/features/download/presentation/bloc/download_event.dart
-
15lib/features/download/presentation/ui/download_page.dart
-
16lib/features/home/presentation/bloc/home_bloc.dart
-
78lib/features/intro/data/datasource/intro_datasource.dart
-
34lib/features/intro/data/repository_impl/intro_repository_impl.dart
-
9lib/features/intro/domain/repository/intro_repository.dart
-
12lib/features/intro/domain/usecases/loading_stream_usecase.dart
-
1lib/features/intro/presentation/bloc/intro_event.dart
-
136lib/features/intro/presentation/ui/widgets/intro_loading_widget.dart
-
1lib/features/language/presentation/bloc/language_bloc.dart
-
15lib/init_bindings.dart
|
After Width: 156 | Height: 174 | Size: 8.2 KiB |
@ -0,0 +1,23 @@ |
|||
import 'dart:async'; |
|||
|
|||
import 'package:flutter/material.dart'; |
|||
import 'package:go_router/go_router.dart'; |
|||
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart'; |
|||
import 'package:hadi_hoda_flutter/core/routers/my_routes.dart'; |
|||
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart'; |
|||
|
|||
class MyMiddlewares { |
|||
static const MyMiddlewares _i = MyMiddlewares._internal(); |
|||
const MyMiddlewares._internal(); |
|||
factory MyMiddlewares() => _i; |
|||
|
|||
static FutureOr<String?> intro(BuildContext context, GoRouterState state) { |
|||
final String? firstDownload = LocalStorage.readData( |
|||
key: MyConstants.firstDownload); |
|||
if (firstDownload != 'true') { |
|||
return Routes.languagePage; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
import 'package:flutter/material.dart'; |
|||
|
|||
class RotationAnim extends StatefulWidget { |
|||
const RotationAnim({super.key, required this.child}); |
|||
|
|||
final Widget child; |
|||
|
|||
@override |
|||
State<RotationAnim> createState() => _RotationAnimState(); |
|||
} |
|||
|
|||
class _RotationAnimState extends State<RotationAnim> |
|||
with SingleTickerProviderStateMixin { |
|||
late AnimationController _controller; |
|||
late Animation<double> _animation; |
|||
|
|||
@override |
|||
void initState() { |
|||
super.initState(); |
|||
_controller = AnimationController( |
|||
vsync: this, |
|||
duration: Duration(seconds: 20), |
|||
); |
|||
_animation = Tween<double>( |
|||
begin: 0, |
|||
end: 20, |
|||
).animate(CurvedAnimation(parent: _controller, curve: Curves.linear)); |
|||
|
|||
_controller.repeat(); |
|||
} |
|||
|
|||
@override |
|||
void dispose() { |
|||
_controller.dispose(); |
|||
super.dispose(); |
|||
} |
|||
|
|||
@override |
|||
Widget build(BuildContext context) { |
|||
return AnimatedBuilder( |
|||
animation: _controller, |
|||
child: widget.child, |
|||
builder: (context, child) => RotationTransition( |
|||
turns: _animation, |
|||
alignment: Alignment.center, |
|||
child: child, |
|||
), |
|||
); |
|||
} |
|||
} |
|||
@ -1,10 +1,10 @@ |
|||
import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart'; |
|||
import 'package:hadi_hoda_flutter/features/download/domain/repository/download_repository.dart'; |
|||
|
|||
class LoadingStreamAudioUseCase { |
|||
class LoadingStreamUseCase { |
|||
final IDownloadRepository repository; |
|||
|
|||
const LoadingStreamAudioUseCase(this.repository); |
|||
const LoadingStreamUseCase(this.repository); |
|||
|
|||
Stream<DownloadEntity> call() { |
|||
return repository.loadingStream(); |
|||
@ -1,5 +1,6 @@ |
|||
sealed class DownloadEvent { |
|||
const DownloadEvent(); |
|||
} |
|||
class GetImagesEvent extends DownloadEvent {} |
|||
class GetAudiosEvent extends DownloadEvent {} |
|||
class SaveLevelsEvent extends DownloadEvent {} |
|||
@ -1,78 +0,0 @@ |
|||
import 'dart:async'; |
|||
import 'dart:io'; |
|||
|
|||
import 'package:flutter_archive/flutter_archive.dart'; |
|||
import 'package:hadi_hoda_flutter/core/constants/my_api.dart'; |
|||
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart'; |
|||
import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; |
|||
import 'package:hadi_hoda_flutter/core/network/http_request.dart'; |
|||
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart'; |
|||
import 'package:hadi_hoda_flutter/core/utils/storage_path.dart'; |
|||
import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart'; |
|||
|
|||
abstract class IIntroDatasource { |
|||
Future<void> getImages(); |
|||
Stream<DownloadEntity> loadingStream(); |
|||
} |
|||
|
|||
class IntroDatasourceImpl implements IIntroDatasource { |
|||
final IHttpRequest httpRequest; |
|||
final StreamController<DownloadEntity> streamController = StreamController<DownloadEntity>.broadcast(); |
|||
|
|||
IntroDatasourceImpl(this.httpRequest); |
|||
|
|||
@override |
|||
Future<void> getImages() async { |
|||
final String filePath = '${StoragePath.documentDir.path}/images.zip'; |
|||
|
|||
if (LocalStorage.readData(key: MyConstants.downloadedImage) != 'true') { |
|||
await httpRequest.download( |
|||
urlPath: MyApi.images, |
|||
savePath: filePath, |
|||
onReceive: (count, total) { |
|||
streamController.add(DownloadEntity( |
|||
count: count / 1, |
|||
total: total / 1, |
|||
percent: (count / total) * 100, |
|||
)); |
|||
}, |
|||
).then((value) async { |
|||
await LocalStorage.saveData( |
|||
key: MyConstants.downloadedImage, |
|||
value: 'true', |
|||
); |
|||
}); |
|||
} |
|||
|
|||
try{ |
|||
if (LocalStorage.readData(key: MyConstants.extractedImage) != 'true') { |
|||
final File file = File(filePath); |
|||
final Directory directory = Directory('${StoragePath.documentDir.path}/'); |
|||
await ZipFile.extractToDirectory( |
|||
zipFile: file, |
|||
destinationDir: directory, |
|||
onExtracting: (zipEntry, progress) { |
|||
return ZipFileOperation.includeItem; |
|||
}, |
|||
).then((value) async { |
|||
await Future.wait([ |
|||
LocalStorage.saveData( |
|||
key: MyConstants.extractedImage, |
|||
value: 'true', |
|||
), |
|||
file.delete(recursive: true), |
|||
]); |
|||
}); |
|||
} else { |
|||
streamController.add(DownloadEntity(percent: 50)); |
|||
await Future.delayed(Duration(milliseconds: 150)); |
|||
streamController.add(DownloadEntity(percent: 100)); |
|||
} |
|||
} catch (e){ |
|||
throw MyException(errorMessage: '$e'); |
|||
} |
|||
} |
|||
|
|||
@override |
|||
Stream<DownloadEntity> loadingStream() => streamController.stream; |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
import 'package:flutter/foundation.dart'; |
|||
import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; |
|||
import 'package:hadi_hoda_flutter/core/params/no_params.dart'; |
|||
import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; |
|||
import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart'; |
|||
import 'package:hadi_hoda_flutter/features/intro/data/datasource/intro_datasource.dart'; |
|||
import 'package:hadi_hoda_flutter/features/intro/domain/repository/intro_repository.dart'; |
|||
|
|||
class IntroRepositoryImpl implements IIntroRepository { |
|||
final IIntroDatasource datasource; |
|||
|
|||
const IntroRepositoryImpl(this.datasource); |
|||
|
|||
@override |
|||
Future<DataState<NoParams, MyException>> getImages() async { |
|||
try { |
|||
await datasource.getImages(); |
|||
return DataState.success(NoParams()); |
|||
} on MyException catch (e) { |
|||
return DataState.error(e); |
|||
} catch (e) { |
|||
if (kDebugMode) { |
|||
rethrow; |
|||
} else { |
|||
return DataState.error(MyException(errorMessage: '$e')); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@override |
|||
Stream<DownloadEntity> loadingStream() { |
|||
return datasource.loadingStream(); |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
import 'package:hadi_hoda_flutter/core/error_handler/my_exception.dart'; |
|||
import 'package:hadi_hoda_flutter/core/params/no_params.dart'; |
|||
import 'package:hadi_hoda_flutter/core/utils/data_state.dart'; |
|||
import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart'; |
|||
|
|||
abstract class IIntroRepository { |
|||
Future<DataState<NoParams, MyException>> getImages(); |
|||
Stream<DownloadEntity> loadingStream(); |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart'; |
|||
import 'package:hadi_hoda_flutter/features/intro/domain/repository/intro_repository.dart'; |
|||
|
|||
class LoadingStreamUseCase { |
|||
final IIntroRepository repository; |
|||
|
|||
const LoadingStreamUseCase(this.repository); |
|||
|
|||
Stream<DownloadEntity> call() { |
|||
return repository.loadingStream(); |
|||
} |
|||
} |
|||
@ -1,4 +1,3 @@ |
|||
sealed class IntroEvent { |
|||
const IntroEvent(); |
|||
} |
|||
class GetImagesEvent extends IntroEvent {} |
|||
@ -1,136 +0,0 @@ |
|||
import 'package:flutter/material.dart'; |
|||
import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; |
|||
import 'package:hadi_hoda_flutter/common_ui/resources/my_text_style.dart'; |
|||
import 'package:hadi_hoda_flutter/features/download/domain/entities/download_entity.dart'; |
|||
|
|||
|
|||
class IntroLoadingWidget extends StatelessWidget { |
|||
const IntroLoadingWidget({ |
|||
super.key, |
|||
this.loadingStream, |
|||
}); |
|||
|
|||
final Stream<DownloadEntity>? loadingStream; |
|||
|
|||
@override |
|||
Widget build(BuildContext context) { |
|||
return ClipPath( |
|||
clipper: BubbleClip(), |
|||
child: Container( |
|||
width: 300, |
|||
height: 60, |
|||
padding: EdgeInsets.symmetric( |
|||
vertical: MySpaces.s4, |
|||
horizontal: MySpaces.s2, |
|||
), |
|||
decoration: const BoxDecoration( |
|||
gradient: LinearGradient( |
|||
begin: Alignment(0, 1), // bottom |
|||
end: Alignment(0, -1), // top |
|||
colors: [ |
|||
Color(0xFFCADCFF), // #CADCFF |
|||
Colors.white, // #FFFFFF |
|||
], |
|||
), |
|||
), |
|||
child: StreamBuilder<DownloadEntity>( |
|||
initialData: DownloadEntity(), |
|||
stream: loadingStream, |
|||
builder: (context, snapshot) { |
|||
return Row( |
|||
children: [ |
|||
Expanded( |
|||
flex: 85, |
|||
child: ClipPath( |
|||
clipper: BubbleClip(), |
|||
child: AnimatedContainer( |
|||
duration: const Duration(milliseconds: 300), |
|||
padding: EdgeInsetsDirectional.only( |
|||
end: 260 - ((snapshot.data?.percent ?? 0) * 260 / 100), |
|||
), |
|||
decoration: BoxDecoration( |
|||
color: Color(0xFF1F59BD).withValues(alpha: 0.25), |
|||
), |
|||
child: ClipPath( |
|||
clipper: BubbleClip(), |
|||
child: Container( |
|||
decoration: BoxDecoration( |
|||
gradient: RadialGradient( |
|||
radius: 2, |
|||
colors: [ |
|||
Color(0xFFFFBD00), // #CADCFF |
|||
Color(0xFFFF772C), // #CADCFF |
|||
], |
|||
), |
|||
), |
|||
), |
|||
), |
|||
), |
|||
), |
|||
), |
|||
Expanded( |
|||
flex: 15, |
|||
child: Center( |
|||
child: Text( |
|||
'${snapshot.data?.percent?.toInt() ?? 0}%', |
|||
style: DinoKids.regular17.copyWith( |
|||
color: Color(0XFF6E83A8), |
|||
), |
|||
), |
|||
), |
|||
), |
|||
], |
|||
); |
|||
} |
|||
), |
|||
), |
|||
); |
|||
} |
|||
} |
|||
|
|||
class BubbleClip extends CustomClipper<Path> { |
|||
@override |
|||
Path getClip(Size size) { |
|||
// Original SVG viewBox: 334 x 60 |
|||
const double w0 = 334.0; |
|||
const double h0 = 60.0; |
|||
final sx = size.width / w0; |
|||
final sy = size.height / h0; |
|||
|
|||
// SVG path: |
|||
// M9.82057 10.3597 |
|||
// C -1.70838 17.1589 -3.47995 44.4301 6.60447 53.1719 |
|||
// C 16.0075 61.291 305.076 61.9385 323.201 53.4956 |
|||
// C 341.326 45.0527 332.116 8.04571 324.829 5.7273 |
|||
// C 307.985 -2.06805 28.6539 -0.77294 9.82057 10.3597 |
|||
// Z |
|||
final p = Path() |
|||
..moveTo(9.82057 * sx, 10.3597 * sy) |
|||
..cubicTo( |
|||
-1.70838 * sx, 17.1589 * sy, |
|||
-3.47995 * sx, 44.4301 * sy, |
|||
6.60447 * sx, 53.1719 * sy, |
|||
) |
|||
..cubicTo( |
|||
16.0075 * sx, 61.291 * sy, |
|||
305.076 * sx, 61.9385 * sy, |
|||
323.201 * sx, 53.4956 * sy, |
|||
) |
|||
..cubicTo( |
|||
341.326 * sx, 45.0527 * sy, |
|||
332.116 * sx, 8.04571 * sy, |
|||
324.829 * sx, 5.7273 * sy, |
|||
) |
|||
..cubicTo( |
|||
307.985 * sx, -2.06805 * sy, |
|||
28.6539 * sx, -0.77294 * sy, |
|||
9.82057 * sx, 10.3597 * sy, |
|||
) |
|||
..close(); |
|||
|
|||
return p; |
|||
} |
|||
|
|||
@override |
|||
bool shouldReclip(covariant CustomClipper<Path> oldClipper) => false; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue