mirror of
https://github.com/Iconica-Development/flutter_profile.git
synced 2025-05-18 16:53:45 +02:00
Merge pull request #15 from Iconica-Development/feat-onUploadStateChanged-avatar
feat: onUploadStateChanged avatar
This commit is contained in:
commit
8766b9b848
4 changed files with 33 additions and 9 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
}) {}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue