Bot basis

This commit is contained in:
2025-08-23 17:07:42 +08:00
parent 4beda9200e
commit 178c12b893
14 changed files with 323 additions and 346 deletions

View File

@@ -6,7 +6,7 @@ part of 'apps.dart';
// RiverpodGenerator
// **************************************************************************
String _$customAppsHash() => r'c36e5ee59f16a29220dc0e9fba65e579d341a28f';
String _$customAppsHash() => r'450bedaf4220b8963cb44afeb14d4c0e80f01b11';
/// Copied from Dart SDK
class _SystemHash {

View File

@@ -71,14 +71,19 @@ class BotsScreen extends HookConsumerWidget {
return Card(
margin: const EdgeInsets.all(8.0),
child: ListTile(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
leading: CircleAvatar(
child:
bot.picture != null
? CloudFileWidget(item: bot.picture!)
bot.account.profile.picture != null
? ProfilePictureWidget(
file: bot.account.profile.picture!,
)
: const Icon(Symbols.smart_toy),
),
title: Text(bot.name),
subtitle: Text(bot.description ?? ''),
title: Text(bot.account.nick),
subtitle: Text(bot.account.name),
trailing: PopupMenuButton(
itemBuilder:
(context) => [
@@ -135,13 +140,9 @@ class BotsScreen extends HookConsumerWidget {
},
),
onTap: () {
context.pushNamed(
'developerBotDetail',
pathParameters: {
'name': publisherName,
'projectId': projectId,
'id': bot.id,
},
context.goNamed(
'accountProfile',
pathParameters: {'name': bot.account.name},
);
},
),

View File

@@ -6,7 +6,7 @@ part of 'bots.dart';
// RiverpodGenerator
// **************************************************************************
String _$botsHash() => r'a54c8b4df23f94754398706779044903fcca6eea';
String _$botsHash() => r'15cefd5781350eb68208a342e85fcb0b9e0e3269';
/// Copied from Dart SDK
class _SystemHash {

View File

@@ -6,7 +6,7 @@ part of 'edit_app.dart';
// RiverpodGenerator
// **************************************************************************
String _$customAppHash() => r'17b3d1385e59bc5ee7f13fb0f11c56cf8a9ba41f';
String _$customAppHash() => r'8e1b38f3dc9b04fad362ee1141fcbfc53f008c09';
/// Copied from Dart SDK
class _SystemHash {

View File

@@ -55,31 +55,44 @@ class EditBotScreen extends HookConsumerWidget {
final submitting = useState(false);
final nameController = useTextEditingController();
final nickController = useTextEditingController();
final slugController = useTextEditingController();
final descriptionController = useTextEditingController();
final picture = useState<SnCloudFile?>(null);
final websiteController = useTextEditingController();
final documentationController = useTextEditingController();
final isPublic = useState(false);
final isInteractive = useState(false);
final firstNameController = useTextEditingController();
final middleNameController = useTextEditingController();
final lastNameController = useTextEditingController();
final genderController = useTextEditingController();
final pronounsController = useTextEditingController();
final locationController = useTextEditingController();
final timeZoneController = useTextEditingController();
final bioController = useTextEditingController();
final birthday = useState<DateTime?>(null);
final background = useState<SnCloudFile?>(null);
useEffect(() {
if (botData?.value != null) {
nameController.text = botData!.value!.name;
nameController.text = botData!.value!.account.name;
nickController.text = botData.value!.account.nick;
slugController.text = botData.value!.slug;
descriptionController.text = botData.value!.description ?? '';
picture.value = botData.value!.picture;
websiteController.text = botData.value!.links?.website ?? '';
documentationController.text =
botData.value!.links?.documentation ?? '';
isPublic.value = botData.value!.config?.isPublic ?? false;
isInteractive.value = botData.value!.config?.isInteractive ?? false;
picture.value = botData.value!.account.profile.picture;
background.value = botData.value!.account.profile.background;
// Populate from botData.value.account.profile
firstNameController.text = botData.value!.account.profile.firstName;
middleNameController.text = botData.value!.account.profile.middleName;
lastNameController.text = botData.value!.account.profile.lastName;
genderController.text = botData.value!.account.profile.gender;
pronounsController.text = botData.value!.account.profile.pronouns;
locationController.text = botData.value!.account.profile.location;
timeZoneController.text = botData.value!.account.profile.timeZone;
bioController.text = botData.value!.account.profile.bio;
birthday.value = botData.value!.account.profile.birthday?.toLocal();
}
return null;
}, [botData]);
void setPicture() async {
void setPicture(String position) async {
showLoadingModal(context);
var result = await ref
.read(imagePickerProvider)
@@ -94,7 +107,12 @@ class EditBotScreen extends HookConsumerWidget {
result = await cropImage(
context,
image: result,
allowedAspectRatios: [const CropAspectRatio(height: 1, width: 1)],
allowedAspectRatios: [
if (position == 'background')
const CropAspectRatio(height: 7, width: 16)
else
const CropAspectRatio(height: 1, width: 1),
],
);
if (result == null) {
if (context.mounted) hideLoadingModal(context);
@@ -122,7 +140,12 @@ class EditBotScreen extends HookConsumerWidget {
if (cloudFile == null) {
throw ArgumentError('Failed to upload the file...');
}
picture.value = cloudFile;
switch (position) {
case 'picture':
picture.value = cloudFile;
case 'background':
background.value = cloudFile;
}
} catch (err) {
showErrorAlert(err);
} finally {
@@ -135,37 +158,42 @@ class EditBotScreen extends HookConsumerWidget {
final client = ref.read(apiClientProvider);
final data = {
'name': nameController.text,
'nick': nickController.text,
'slug': slugController.text,
'description': descriptionController.text,
'picture_id': picture.value?.id,
'config': {
'is_public': isPublic.value,
'is_interactive': isInteractive.value,
},
'links': {
'website':
websiteController.text.isNotEmpty ? websiteController.text : null,
'documentation':
documentationController.text.isNotEmpty
? documentationController.text
: null,
},
'background_id': background.value?.id,
'first_name': firstNameController.text,
'middle_name': middleNameController.text,
'last_name': lastNameController.text,
'gender': genderController.text,
'pronouns': pronounsController.text,
'location': locationController.text,
'time_zone': timeZoneController.text,
'bio': bioController.text,
'birthday': birthday.value?.toUtc().toIso8601String(),
};
if (isNew) {
await client.post(
'/develop/developers/$publisherName/projects/$projectId/bots',
data: data,
);
} else {
await client.patch(
'/develop/developers/$publisherName/projects/$projectId/bots/$id',
data: data,
);
}
try {
showLoadingModal(context);
if (isNew) {
await client.post(
'/develop/developers/$publisherName/projects/$projectId/bots',
data: data,
);
} else {
await client.patch(
'/develop/developers/$publisherName/projects/$projectId/bots/$id',
data: data,
);
}
if (context.mounted) {
context.pop();
if (context.mounted) {
context.pop();
}
} catch (err) {
showErrorAlert(err);
} finally {
if (context.mounted) hideLoadingModal(context);
}
}
@@ -186,22 +214,44 @@ class EditBotScreen extends HookConsumerWidget {
child: Column(
children: [
AspectRatio(
aspectRatio: 1,
child: GestureDetector(
onTap: setPicture,
child: Container(
color:
Theme.of(
context,
).colorScheme.surfaceContainerHigh,
child:
picture.value != null
? CloudFileWidget(
item: picture.value!,
fit: BoxFit.cover,
)
: const Icon(Symbols.smart_toy, size: 48),
),
aspectRatio: 16 / 7,
child: Stack(
clipBehavior: Clip.none,
fit: StackFit.expand,
children: [
GestureDetector(
child: Container(
color:
Theme.of(
context,
).colorScheme.surfaceContainerHigh,
child:
background.value != null
? CloudFileWidget(
item: background.value!,
fit: BoxFit.cover,
)
: const SizedBox.shrink(),
),
onTap: () {
setPicture('background');
},
),
Positioned(
left: 20,
bottom: -32,
child: GestureDetector(
child: ProfilePictureWidget(
fileId: picture.value?.id,
radius: 40,
fallbackIcon: Symbols.smart_toy,
),
onTap: () {
setPicture('picture');
},
),
),
],
),
).padding(bottom: 32),
Form(
@@ -213,6 +263,14 @@ class EditBotScreen extends HookConsumerWidget {
decoration: InputDecoration(labelText: 'name'.tr()),
),
const SizedBox(height: 16),
TextFormField(
controller: nickController,
decoration: InputDecoration(
labelText: 'nickname'.tr(),
alignLabelWithHint: true,
),
),
const SizedBox(height: 16),
TextFormField(
controller: slugController,
decoration: InputDecoration(
@@ -222,41 +280,129 @@ class EditBotScreen extends HookConsumerWidget {
),
const SizedBox(height: 16),
TextFormField(
controller: descriptionController,
controller: bioController,
decoration: InputDecoration(
labelText: 'description'.tr(),
labelText: 'bio'.tr(),
alignLabelWithHint: true,
),
maxLines: 3,
),
const SizedBox(height: 16),
TextFormField(
controller: websiteController,
decoration: InputDecoration(
labelText: 'websiteUrl'.tr(),
hintText: 'https://example.com',
),
keyboardType: TextInputType.url,
Row(
spacing: 16,
children: [
Expanded(
child: TextFormField(
controller: firstNameController,
decoration: InputDecoration(
labelText: 'firstName'.tr(),
),
),
),
Expanded(
child: TextFormField(
controller: middleNameController,
decoration: InputDecoration(
labelText: 'middleName'.tr(),
),
),
),
Expanded(
child: TextFormField(
controller: lastNameController,
decoration: InputDecoration(
labelText: 'lastName'.tr(),
),
),
),
],
),
const SizedBox(height: 16),
TextFormField(
controller: documentationController,
decoration: InputDecoration(
labelText: 'documentationUrl'.tr(),
hintText: 'https://example.com/docs',
),
keyboardType: TextInputType.url,
Row(
spacing: 16,
children: [
Expanded(
child: TextFormField(
controller: genderController,
decoration: InputDecoration(
labelText: 'gender'.tr(),
),
),
),
Expanded(
child: TextFormField(
controller: pronounsController,
decoration: InputDecoration(
labelText: 'pronouns'.tr(),
),
),
),
],
),
const SizedBox(height: 16),
SwitchListTile(
title: Text('isPublic').tr(),
value: isPublic.value,
onChanged: (value) => isPublic.value = value,
Row(
spacing: 16,
children: [
Expanded(
child: TextFormField(
controller: locationController,
decoration: InputDecoration(
labelText: 'location'.tr(),
),
),
),
Expanded(
child: TextFormField(
controller: timeZoneController,
decoration: InputDecoration(
labelText: 'timeZone'.tr(),
),
),
),
],
),
SwitchListTile(
title: Text('isInteractive').tr(),
value: isInteractive.value,
onChanged: (value) => isInteractive.value = value,
const SizedBox(height: 16),
GestureDetector(
onTap: () async {
final date = await showDatePicker(
context: context,
initialDate: birthday.value ?? DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime.now(),
);
if (date != null) {
birthday.value = date;
}
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Theme.of(context).dividerColor,
width: 1,
),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'birthday'.tr(),
style: TextStyle(
color: Theme.of(context).hintColor,
),
),
Text(
birthday.value != null
? DateFormat.yMMMd().format(
birthday.value!,
)
: 'Select a date'.tr(),
),
],
),
),
),
const SizedBox(height: 16),
Align(
@@ -264,7 +410,7 @@ class EditBotScreen extends HookConsumerWidget {
child: TextButton.icon(
onPressed:
submitting.value ? null : performAction,
label: Text('saveChanges'.tr()),
label: Text('saveChanges').tr(),
icon: const Icon(Symbols.save),
),
),

View File

@@ -6,7 +6,7 @@ part of 'edit_bot.dart';
// RiverpodGenerator
// **************************************************************************
String _$botHash() => r'a3e412ed575c513434bc718b7920db1d017111f4';
String _$botHash() => r'7bec47bb2a4061a5babc6d6d19c3d4c320c91188';
/// Copied from Dart SDK
class _SystemHash {

View File

@@ -6,7 +6,7 @@ part of 'edit_project.dart';
// RiverpodGenerator
// **************************************************************************
String _$devProjectHash() => r'fc68254c6e598e3fa05c86c36f1469c0b689bc43';
String _$devProjectHash() => r'd92be3f5cdc510c2a377615ed5c70622a6842bf2';
/// Copied from Dart SDK
class _SystemHash {

View File

@@ -61,6 +61,10 @@ class DevProjectsScreen extends HookConsumerWidget {
return Card(
margin: const EdgeInsets.all(8.0),
child: ListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
contentPadding: EdgeInsets.only(left: 20, right: 12),
title: Text(project.name),
subtitle: Text(project.description ?? ''),
trailing: PopupMenuButton(

View File

@@ -6,7 +6,7 @@ part of 'projects.dart';
// RiverpodGenerator
// **************************************************************************
String _$devProjectsHash() => r'4c86ea5c3c02185514dbfa32804f1529f68d56c7';
String _$devProjectsHash() => r'87fdcab47cd7d79ab019a5625617abeb1ffa1f39';
/// Copied from Dart SDK
class _SystemHash {