Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Feature/upgrade flutter 2 #547

Open
wants to merge 6 commits into
base: develop
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
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import 'package:Okuna/services/universal_links/universal_links.dart';
import 'package:Okuna/widgets/toast.dart';
import 'package:Okuna/translation/constants.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';
import 'package:flutter\_localizations/flutter\_localizations.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'dart:async';
Expand Down Expand Up @@ -67,7 +66,8 @@ class _MyAppState extends State<MyApp> {
}

void bootstrap() {
DiskCache().maxEntries = MAX_NETWORK_IMAGE_CACHE_ENTRIES;

// DiskCache().maxEntries = MAX_NETWORK_IMAGE_CACHE_ENTRIES;
//DiskCache().maxSizeBytes = MAX_NETWORK_IMAGE_CACHE_MB * 1000000; // 200mb
}

Expand Down
7 changes: 5 additions & 2 deletions lib/pages/home/bottom_sheets/camera_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class OBCameraPickerBottomSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
final _picker = ImagePicker();
var provider = OpenbookProvider.of(context);

LocalizationService localizationService = provider.localizationService;
Expand All @@ -28,7 +29,8 @@ class OBCameraPickerBottomSheet extends StatelessWidget {
bool permissionGranted = await provider.permissionService
.requestStoragePermissions(context: context);
if (permissionGranted) {
File file = await ImagePicker.pickImage(source: ImageSource.camera);
final pickedFile = await _picker.getImage(source: ImageSource.camera);
final File file = File(pickedFile.path);
Navigator.pop(
context, file != null ? MediaFile(file, FileType.image) : null);
}
Expand All @@ -43,7 +45,8 @@ class OBCameraPickerBottomSheet extends StatelessWidget {
bool permissionGranted = await provider.permissionService
.requestStoragePermissions(context: context);
if (permissionGranted) {
File file = await ImagePicker.pickVideo(source: ImageSource.camera);
final pickedFile = await _picker.getVideo(source: ImageSource.camera);
final File file = File(pickedFile.path);
Navigator.pop(
context, file != null ? MediaFile(file, FileType.video) : null);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/pages/home/bottom_sheets/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class OBImagePickerBottomSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
final _picker = ImagePicker();
var provider = OpenbookProvider.of(context);

LocalizationService localizationService = provider.localizationService;
Expand Down Expand Up @@ -47,9 +48,9 @@ class OBImagePickerBottomSheet extends StatelessWidget {
bool permissionGranted = await provider.permissionService
.requestCameraPermissions(context: context);
if (permissionGranted) {
File pickedImage =
await ImagePicker.pickImage(source: ImageSource.camera);
Navigator.pop(context, pickedImage);
final pickedFile = await _picker.getImage(source: ImageSource.camera);
final File file = File(pickedFile.path);
Navigator.pop(context, file);
}
},
)
Expand Down
9 changes: 5 additions & 4 deletions lib/pages/home/bottom_sheets/video_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class OBVideoPickerBottomSheet extends StatelessWidget {

@override
Widget build(BuildContext context) {
final _picker = ImagePicker();
var provider = OpenbookProvider.of(context);

LocalizationService localizationService = provider.localizationService;
Expand Down Expand Up @@ -45,10 +46,10 @@ class OBVideoPickerBottomSheet extends StatelessWidget {
onTap: () async {
bool permissionGranted = await provider.permissionService
.requestCameraPermissions(context: context);
if (permissionGranted) {
File pickedVideo =
await ImagePicker.pickVideo(source: ImageSource.camera);
Navigator.pop(context, pickedVideo);
if (permissionGranted) {
final pickedFile = await _picker.getVideo(source: ImageSource.camera);
final File file = File(pickedFile.path);
Navigator.pop(context, file);
}
},
)
Expand Down
52 changes: 37 additions & 15 deletions lib/pages/home/modals/save_post/widgets/post_image_previewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import 'dart:io';

import 'package:Okuna/models/post_image.dart';
import 'package:Okuna/provider.dart';
import 'package:Okuna/widgets/progress_indicator.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';

class OBPostImagePreviewer extends StatelessWidget {
final PostImage postImage;
Expand Down Expand Up @@ -34,20 +35,41 @@ class OBPostImagePreviewer extends StatelessWidget {
height: 200.0,
width: 200,
child: ClipRRect(
borderRadius: new BorderRadius.circular(avatarBorderRadius),
child: isFileImage
? Image.file(
postImageFile,
fit: BoxFit.cover,
)
: Image(
fit: BoxFit.cover,
image: AdvancedNetworkImage(postImage.image,
useDiskCache: true,
fallbackAssetImage:
'assets/images/fallbacks/post-fallback.png',
retryLimit: 0),
)));
borderRadius: new BorderRadius.circular(avatarBorderRadius),
child: isFileImage
? Image.file(
postImageFile,
fit: BoxFit.cover,
)
: ExtendedImage.network(
postImage.image,
fit: BoxFit.cover,
cache: true,
retries: 0,
loadStateChanged: (ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
return OBProgressIndicator();
break;
case LoadState.completed:
return null;
break;
case LoadState.failed:
return Image.asset(
"assets/images/fallbacks/post-fallback.png",
fit: BoxFit.cover,
);
break;
default:
return Image.asset(
"assets/images/fallbacks/post-fallback.png",
fit: BoxFit.cover,
);
break;
}
},
),
));

if (onRemove == null) return imagePreview;

Expand Down
39 changes: 31 additions & 8 deletions lib/pages/home/modals/save_post/widgets/post_video_previewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import 'dart:io';
import 'package:Okuna/models/post_video.dart';
import 'package:Okuna/models/video_format.dart';
import 'package:Okuna/provider.dart';
import 'package:Okuna/widgets/progress_indicator.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';

class OBPostVideoPreview extends StatelessWidget {
final File postVideoFile;
Expand Down Expand Up @@ -40,13 +41,35 @@ class OBPostVideoPreview extends StatelessWidget {
fit: BoxFit.cover,
));
})
: _wrapImageWidgetForThumbnail(Image(
fit: BoxFit.cover,
image: AdvancedNetworkImage(postVideo.thumbnail,
useDiskCache: true,
fallbackAssetImage: 'assets/images/fallbacks/post-fallback.png',
retryLimit: 0),
));
: _wrapImageWidgetForThumbnail(
ExtendedImage.network(
postVideo.thumbnail,
fit: BoxFit.cover,
cache: true,
loadStateChanged: (ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
return OBProgressIndicator();
break;
case LoadState.completed:
return null;
break;
case LoadState.failed:
return Image.asset(
"assets/images/fallbacks/post-fallback.png",
fit: BoxFit.cover,
);
break;
default:
return Image.asset(
"assets/images/fallbacks/post-fallback.png",
fit: BoxFit.cover,
);
break;
}
},
),
);

return Stack(
children: <Widget>[
Expand Down
42 changes: 29 additions & 13 deletions lib/pages/home/modals/zoomable_photo.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:Okuna/widgets/icon.dart';
import 'package:Okuna/widgets/page_scaffold.dart';
import 'package:Okuna/widgets/progress_indicator.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';
import 'package:photo_view/photo_view.dart';
import 'package:pigment/pigment.dart';
import "dart:math" show pi;

class OBZoomablePhotoModal extends StatefulWidget {
Expand Down Expand Up @@ -61,7 +61,6 @@ class OBZoomablePhotoModalState extends State<OBZoomablePhotoModal>

@override
Widget build(BuildContext context) {

return WillPopScope(
child: OBCupertinoPageScaffold(
backgroundColor: Colors.black26,
Expand Down Expand Up @@ -123,17 +122,34 @@ class OBZoomablePhotoModalState extends State<OBZoomablePhotoModal>
key: Key(widget.imageUrl),
enableRotation: false,
scaleStateChangedCallback: _photoViewScaleStateChangedCallback,
imageProvider: AdvancedNetworkImage(widget.imageUrl,
retryLimit: 0,
useDiskCache: true,
getRealUrl: () {
return Future.delayed((Duration(milliseconds: 0)),() => widget.imageUrl);
imageProvider: ExtendedImage.network(
widget.imageUrl,
fit: BoxFit.cover,
cacheMaxAge: const Duration(days: 7),
cache: true,
loadStateChanged: (ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
return OBProgressIndicator();
break;
case LoadState.completed:
return null;
break;
case LoadState.failed:
return Image.asset(
"assets/images/fallbacks/post-fallback.png",
fit: BoxFit.cover,
);
break;
default:
return Image.asset(
"assets/images/fallbacks/post-fallback.png",
fit: BoxFit.cover,
);
break;
}
},
cacheRule: CacheRule(
maxAge: const Duration(days: 7),
checksum: true,
),
fallbackAssetImage: 'assets/images/fallbacks/post-fallback.png'),
).image,
maxScale: PhotoViewComputedScale.covered,
minScale: PhotoViewComputedScale.contained,
),
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/home/pages/communities/widgets/category_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:Okuna/models/category.dart';
import 'package:Okuna/provider.dart';
import 'package:Okuna/services/theme_value_parser.dart';
import 'package:Okuna/widgets/tabs/image_tab.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';

class OBCategoryTab extends StatelessWidget {
final Category category;
Expand All @@ -22,8 +22,10 @@ class OBCategoryTab extends StatelessWidget {
text: category.title,
color: categoryColor,
textColor: categoryColorIsDark ? Colors.white : Colors.black,
imageProvider:
AdvancedNetworkImage(category.avatar, useDiskCache: true),
imageProvider: ExtendedNetworkImageProvider(
category.avatar,
cache: true,
),
);
}
}
10 changes: 5 additions & 5 deletions lib/services/httpie.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class HttpieService {
Response response;

try {
response = await client.post(url,
response = await client.post(Uri.parse(url),
headers: finalHeaders, body: body, encoding: encoding);
} catch (error) {
_handleRequestError(error);
Expand All @@ -102,7 +102,7 @@ class HttpieService {
Response response;

try {
response = await client.put(url,
response = await client.put(Uri.parse(url),
headers: finalHeaders, body: body, encoding: encoding);
} catch (error) {
_handleRequestError(error);
Expand All @@ -124,7 +124,7 @@ class HttpieService {
Response response;

try {
response = await client.patch(url,
response = await client.patch(Uri.parse(url),
headers: finalHeaders, body: body, encoding: encoding);
} catch (error) {
_handleRequestError(error);
Expand All @@ -145,7 +145,7 @@ class HttpieService {
Response response;

try {
response = await client.delete(url, headers: finalHeaders);
response = await client.delete(Uri.parse(url), headers: finalHeaders);
} catch (error) {
_handleRequestError(error);
}
Expand Down Expand Up @@ -230,7 +230,7 @@ class HttpieService {
Response response;

try {
response = await client.get(url, headers: finalHeaders);
response = await client.get(Uri.parse(url), headers: finalHeaders);
} catch (error) {
_handleRequestError(error);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/services/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ import 'package:Okuna/services/user_invites_api.dart';
import 'package:Okuna/services/waitlist_service.dart';
import 'package:crypto/crypto.dart';
import 'package:device_info/device_info.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_advanced_networkimage/provider.dart';
import 'package:meta/meta.dart';
import 'package:rxdart/rxdart.dart';
export 'package:Okuna/services/httpie.dart';
Expand Down Expand Up @@ -248,7 +248,7 @@ class UserService {
Future<void> clearCache() async {
await _removeStoredFirstPostsData();
await _removeStoredTopPostsData();
await DiskCache().clear();
clearMemoryImageCache();
await clearTemporaryDirectories();
Post.clearCache();
User.clearNavigationCache();
Expand Down
Loading