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

feat: add YaruSearchField and YaruSearchTitleField #734

Merged
merged 21 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions example/lib/example_page_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'pages/page_indicator.dart';
import 'pages/popup_page.dart';
import 'pages/progress_indicator_page.dart';
import 'pages/radio_page.dart';
import 'pages/search_field_page.dart';
import 'pages/section_page.dart';
import 'pages/selectable_container_page.dart';
import 'pages/switch_page.dart';
Expand Down Expand Up @@ -182,6 +183,15 @@ final examplePageItems = <PageItem>[
? const Icon(YaruIcons.radiobox_checked_filled)
: const Icon(YaruIcons.radiobox_checked),
),
PageItem(
title: 'YaruSearchField',
snippetUrl:
'https://raw.githubusercontent.com/ubuntu/yaru_widgets.dart/main/example/lib/pages/search_field_page.dart',
iconBuilder: (context, selected) => selected
? const Icon(YaruIcons.search_filled)
: const Icon(YaruIcons.search),
pageBuilder: (_) => const SearchFieldPage(),
),
PageItem(
title: 'YaruSection',
snippetUrl:
Expand Down
92 changes: 92 additions & 0 deletions example/lib/pages/search_field_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import 'package:flutter/material.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

class SearchFieldPage extends StatefulWidget {
const SearchFieldPage({super.key});

@override
State<SearchFieldPage> createState() => _SearchFieldPageState();
}

class _SearchFieldPageState extends State<SearchFieldPage> {
var _titleSearchActive = false;
var _fieldSearchActive = false;

String _titleText = 'The text you submitted';
String _fieldText = 'Or the things you changed';

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final light = theme.brightness == Brightness.light;

return Center(
child: ListView(
children: [
SimpleDialog(
shadowColor: light ? Colors.black : null,
titlePadding: EdgeInsets.zero,
title: YaruDialogTitleBar(
titleSpacing: 0,
centerTitle: true,
title: YaruSearchTitleField(
text: _titleText,
onClear: () => setState(() => _titleText = ''),
onSubmitted: (value) =>
setState(() => _titleText = value ?? ''),
searchActive: _titleSearchActive,
onSearchActive: () =>
setState(() => _titleSearchActive = !_titleSearchActive),
title: const Text(
'Any Widget Here',
),
),
),
children: [
SizedBox(
height: 300,
width: 450,
child: Center(
child: Text(
_titleText,
),
),
)
],
),
SimpleDialog(
shadowColor: light ? Colors.black : null,
titlePadding: EdgeInsets.zero,
title: YaruDialogTitleBar(
heroTag: 'bar2',
titleSpacing: 0,
centerTitle: true,
title: _fieldSearchActive
? YaruSearchField(
onClear: () {},
onChanged: (value) => setState(
() => _fieldText = value,
),
)
: const Text('Title'),
leading: YaruSearchButton(
searchActive: _fieldSearchActive,
onPressed: () =>
setState(() => _fieldSearchActive = !_fieldSearchActive),
),
),
children: [
SizedBox(
height: 300,
width: 450,
child: Center(
child: Text(_fieldText),
),
)
],
),
],
),
);
}
}
6 changes: 6 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ const kYaruButtonRadius = 6.0;
/// The default breakpoint width [YaruMasterDetailPage] uses for switching
/// between portrait and landscape modes.
const kYaruMasterDetailBreakpoint = 620.0;

/// The best height for any item inside a [YaruTitleBar]
const kYaruTitleBarItemHeight = 35.0;

/// The default icon size
const kYaruIconSize = 16.0;
Loading