Skip to content

Commit

Permalink
fix widgetbook
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecoomber committed Oct 16, 2024
1 parent a3dfd3c commit da23afa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 106 deletions.
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Foundation

import path_provider_foundation
import shared_preferences_foundation
import sqflite_darwin
import sqflite
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand Down
1 change: 0 additions & 1 deletion example/widgetbook/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class _HotReloadState extends State<HotReload> {
useCases: [
WidgetbookUseCase(name: 'Default', builder: (context) => defaultTopAppBarUseCase(context)),
WidgetbookUseCase(name: 'Search', builder: (context) => searchTopAppBarUseCase(context)),
WidgetbookUseCase(name: 'Extended', builder: (context) => extendedTopAppBarUseCase(context)),
],
),
WidgetbookComponent(
Expand Down
105 changes: 3 additions & 102 deletions example/widgetbook/pages/components/top_app_bar_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Widget defaultTopAppBarUseCase(BuildContext context) {
label: "Title Alignment",
options: [
ZetaTopAppBarType.defaultAppBar,
ZetaTopAppBarType.centeredTitle,
ZetaTopAppBarType.centered,
],
initialOption: ZetaTopAppBarType.defaultAppBar,
labelBuilder: (option) {
Expand Down Expand Up @@ -84,7 +84,7 @@ class _SearchUseCaseState extends State<_SearchUseCase> {
label: "Title Alignment",
options: [
ZetaTopAppBarType.defaultAppBar,
ZetaTopAppBarType.centeredTitle,
ZetaTopAppBarType.centered,
],
initialOption: ZetaTopAppBarType.defaultAppBar,
labelBuilder: (option) {
Expand All @@ -101,7 +101,7 @@ class _SearchUseCaseState extends State<_SearchUseCase> {
initialValue: false,
);

return ZetaTopAppBar(
return ZetaTopAppBar.search(
leading: IconButton(
onPressed: () {},
icon: ZetaIcon(leadingIcon),
Expand All @@ -118,105 +118,6 @@ class _SearchUseCaseState extends State<_SearchUseCase> {
searchController.text = generatedText;
}
: null,
actions: [
IconButton(
onPressed: () {
searchController.isEnabled ? searchController.closeSearch() : searchController.startSearch();
},
icon: ZetaIcon(ZetaIcons.search)),
],
);
}
}

Widget extendedTopAppBarUseCase(BuildContext context) => ExtendedSearch();

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

@override
State<ExtendedSearch> createState() => _ExtendedSearchState();
}

class _ExtendedSearchState extends State<ExtendedSearch> {
final _searchControllerExtended = ZetaSearchController();

void _showHideSearchExtended() {
_searchControllerExtended.isEnabled
? _searchControllerExtended.closeSearch()
: _searchControllerExtended.startSearch();
}

@override
Widget build(BuildContext context) {
final title = context.knobs.string(label: "Title", initialValue: "Title");

final leadingIcon = iconKnob(context, name: 'Leading Icon', initial: ZetaIcons.hamburger_menu);

final showSearch = context.knobs.boolean(label: 'Search variant', initialValue: false);

return WidgetbookScaffold(
removeBody: true,
builder: (context, constraints) => SafeArea(
child: SizedBox(
width: constraints.maxWidth,
height: constraints.maxHeight,
child: CustomScrollView(
slivers: [
ZetaTopAppBar.extended(
leading: IconButton(icon: ZetaIcon(leadingIcon), onPressed: () {}),
title: Text(title),
actions: showSearch
? [
IconButton(
onPressed: _showHideSearchExtended,
icon: ZetaIcon(ZetaIcons.search),
)
]
: [
IconButton(
onPressed: () {},
icon: ZetaIcon(Icons.language),
),
IconButton(
onPressed: () {},
icon: ZetaIcon(Icons.favorite),
),
IconButton(
onPressed: () {},
icon: ZetaIcon(ZetaIcons.more_vertical),
)
],
searchController: showSearch ? _searchControllerExtended : null,
onSearch: showSearch ? (text) => debugPrint('search text: $text') : null,
onSearchMicrophoneIconPressed: showSearch
? () async {
var sampleTexts = [
'This is a sample text',
'Another sample',
'Speech recognition text',
'Example'
];
var generatedText = sampleTexts[Random().nextInt(sampleTexts.length)];
_searchControllerExtended.text = generatedText;
}
: null,
),
SliverToBoxAdapter(
child: Container(
width: constraints.maxWidth,
height: constraints.maxHeight * 4,
color: Zeta.of(context).colors.surfaceSecondary,
child: CustomPaint(
painter: Painter(context: context, constraints: constraints),
size: Size(constraints.maxWidth, constraints.maxHeight * 4),
),
),
),
],
),
),
),
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/src/components/top_app_bar/top_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ class ZetaTopAppBar extends ZetaStatefulWidget implements PreferredSizeWidget {
shrinks = false;

/// Creates a ZetaTopAppBar with an expanding search field.
/// This will append a search icon to the right of the app bar.
/// When the search icon is pressed, the search field will expand and replace the title widget.
/// It will replace the leading widget with a back button which closes the search field.
/// The search field can be controlled externally by the [searchController].
const ZetaTopAppBar.search({
super.key,
super.rounded,
this.type = ZetaTopAppBarType.defaultAppBar,
this.automaticallyImplyLeading = true,
this.searchController,
this.leading,
Expand All @@ -69,8 +74,8 @@ class ZetaTopAppBar extends ZetaStatefulWidget implements PreferredSizeWidget {
this.searchHintText,
this.onSearchMicrophoneIconPressed,
this.actions = const [],
}) : type = ZetaTopAppBarType.centered,
shrinks = false;
}) : shrinks = false,
assert(type != ZetaTopAppBarType.extended, 'Search app bars cannot be extended');

/// Creates a ZetaTopAppBar with an extended title over 2 lines.
///
Expand Down

0 comments on commit da23afa

Please sign in to comment.