Merge pull request #15 from Iconica-Development/feat-onUploadStateChanged-avatar

feat: onUploadStateChanged avatar
This commit is contained in:
Stein Milder 2022-11-25 13:16:21 +01:00 committed by GitHub
commit 8766b9b848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 9 deletions

View file

@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_profile/flutter_profile.dart';
@ -23,7 +24,8 @@ class ExampleProfileService extends ProfileService {
}
@override
Future<void> uploadImage(BuildContext context) async {
FutureOr<void> uploadImage(BuildContext context,
{required Function(bool isUploading) onUploadStateChanged}) {
debugPrint('Updating avatar');
}
}

View file

@ -3,7 +3,6 @@
// SPDX-License-Identifier: BSD-3-Clause
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_profile/src/models/user.dart';
@ -21,5 +20,8 @@ abstract class ProfileService {
FutureOr<void> editProfile(User user, String key, String? value);
FutureOr<void> uploadImage(BuildContext context);
FutureOr<void> uploadImage(
BuildContext context, {
required Function(bool isUploading) onUploadStateChanged,
});
}

View file

@ -49,9 +49,9 @@ class ProfileWrapper extends StatefulWidget {
class _ProfileWrapperState extends State<ProfileWrapper> {
List<Widget> defaultItems = [];
GlobalKey<FormState> formKey = GlobalKey<FormState>();
Map<String, dynamic> formValues = {};
bool _isUploadingImage = false;
late final Widget child;
@override
@ -215,13 +215,28 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
children: [
if (widget.showAvatar) ...[
InkWell(
onTap: () async {
await widget.service.uploadImage(context);
},
onTap: () => widget.service.uploadImage(
context,
onUploadStateChanged: (isUploading) => setState(
() {
_isUploadingImage = isUploading;
},
),
),
child: AvatarWrapper(
user: widget.user,
textStyle: widget.style.avatarTextStyle,
customAvatar: widget.customAvatar,
customAvatar: _isUploadingImage
? Container(
width: 100,
height: 100,
decoration: const BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
child: const CircularProgressIndicator(),
)
: widget.customAvatar,
),
),
SizedBox(

View file

@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: BSD-3-Clause
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_profile/flutter_profile.dart';
@ -19,5 +21,8 @@ class TestProfileService extends ProfileService {
) {}
@override
Future<void> uploadImage(BuildContext context) async {}
FutureOr<void> uploadImage(
BuildContext context, {
required Function(bool isUploading) onUploadStateChanged,
}) {}
}