Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement spreed #366

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(neon_framework): Implement AutoComplete
Signed-off-by: jld3103 <[email protected]>
  • Loading branch information
provokateurin committed Mar 7, 2024
commit a7300c108b168996f08b3aab82717f8c8d7282d5
95 changes: 95 additions & 0 deletions packages/neon_framework/lib/src/widgets/autocomplete.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ignore_for_file: public_member_api_docs

import 'package:built_collection/built_collection.dart';
import 'package:flutter/material.dart';
import 'package:neon_framework/src/models/account.dart';
import 'package:neon_framework/src/widgets/group_avatar.dart';
import 'package:neon_framework/src/widgets/user_avatar.dart';
import 'package:nextcloud/core.dart' as core;

class NeonAutocomplete extends StatelessWidget {
const NeonAutocomplete({
required this.account,
required this.itemType,
required this.itemId,
required this.shareTypes,
required this.onSelected,
this.sorter,
this.limit = 10,
this.validator,
this.decoration,
this.onFieldSubmitted,
super.key,
});

final Account account;

final String itemType;
final String itemId;
final List<core.ShareType> shareTypes;
final void Function(core.AutocompleteResult entry) onSelected;
final String? sorter;
final int limit;
final FormFieldValidator<String>? validator;
final InputDecoration? decoration;
final ValueChanged<String>? onFieldSubmitted;

@override
Widget build(BuildContext context) => Autocomplete<core.AutocompleteResult>(
fieldViewBuilder: (
context,
controller,
focusNode,
onFieldSubmitted,
) =>
TextFormField(
controller: controller,
focusNode: focusNode,
validator: validator,
decoration: decoration,
onFieldSubmitted: (value) {
onFieldSubmitted();
this.onFieldSubmitted?.call(value);
},
),
optionsBuilder: (text) async {
final result = await account.client.core.autoComplete.$get(
search: text.text,
itemType: itemType,
itemId: itemId,
shareTypes: BuiltList(shareTypes.map((s) => s.index)),
);
return result.body.ocs.data;
},
displayStringForOption: (option) => option.id,
optionsViewBuilder: (context, onSelected, options) => Material(
elevation: 4,
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (context, index) {
final option = options.elementAt(index);
Widget? icon;
switch (option.source) {
case 'users':
icon = NeonUserAvatar(
username: option.id,
);
case 'groups':
icon = const NeonGroupAvatar();
}
return ListTile(
title: Text(option.label),
subtitle: Text(option.id),
leading: icon,
onTap: () {
onSelected(option);
},
);
},
),
),
onSelected: onSelected,
);
}
30 changes: 30 additions & 0 deletions packages/neon_framework/lib/src/widgets/group_avatar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ignore_for_file: public_member_api_docs

import 'package:flutter/material.dart';
import 'package:neon_framework/src/theme/sizes.dart';

class NeonGroupAvatar extends StatelessWidget {
const NeonGroupAvatar({
this.icon = Icons.group,
this.backgroundColor,
this.foregroundColor,
this.size = smallIconSize,
super.key,
});

final IconData icon;
final Color? backgroundColor;
final Color? foregroundColor;
final double size;

@override
Widget build(BuildContext context) => CircleAvatar(
radius: size,
backgroundColor: backgroundColor,
child: Icon(
icon,
color: foregroundColor,
size: size,
),
);
}
2 changes: 2 additions & 0 deletions packages/neon_framework/lib/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export 'package:neon_framework/src/widgets/autocomplete.dart';
export 'package:neon_framework/src/widgets/custom_background.dart';
export 'package:neon_framework/src/widgets/dialog.dart'
hide AccountDeletion, NeonAccountDeletionDialog, NeonAccountSelectionDialog, NeonUnifiedPushDialog;
export 'package:neon_framework/src/widgets/error.dart';
export 'package:neon_framework/src/widgets/group_avatar.dart';
export 'package:neon_framework/src/widgets/image.dart' hide NeonImage;
export 'package:neon_framework/src/widgets/linear_progress_indicator.dart';
export 'package:neon_framework/src/widgets/list_view.dart';
2 changes: 1 addition & 1 deletion packages/neon_framework/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ dependencies:
sdk: flutter
flutter_material_design_icons: ^1.0.0
flutter_native_splash: ^2.0.0
flutter_parsed_text: ^2.0.0
flutter_parsed_text: ^2.1.0
flutter_svg: ^2.0.0
flutter_zxing: ^1.0.0
go_router: ^13.0.0