Skip to content

Commit

Permalink
Merge branch 'main' into rajiv/perparing-for-publish-in-pub.dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/components/checkbox_row/checkbox_row.dart
#	lib/components/email_field/email_field.dart
#	lib/components/menu_item/menu_item.dart
#	lib/components/toggle_row/toggle_row.dart
  • Loading branch information
rajivmanivannan committed Feb 15, 2024
2 parents e147148 + 2952f18 commit 12dc14e
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Tarka UI Kit is a reusable component library for building Flutter apps, based on
- TUINavigationRow
- TUIRadioButton
- TUIRangeSlider
- TUISearchBar
- TUISelectionCard
- TUISlider
- TUISnackBar
Expand Down
19 changes: 19 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:tarka_ui/components/chip/chip.dart';
import 'package:tarka_ui/components/draggable_card/draggable_card.dart';
import 'package:tarka_ui/components/email_field/email_field.dart';
import 'package:tarka_ui/components/menu_item/menu_item.dart';
import 'package:tarka_ui/components/search_bar/search_bar.dart';
import 'package:tarka_ui/components/selection_card/selection_card.dart';
import 'package:tarka_ui/components/toggle_row/toggle_row.dart';
import 'package:tarka_ui/styles/theme.dart';
Expand Down Expand Up @@ -1199,6 +1200,24 @@ class _HomePageState extends State<HomePage> {
});
},
),
const SizedBox(height: 8),
const Text("Search Bar", style: TUITextStyle.heading6),
const SizedBox(height: 8),
TUISearchBar(
showBackIcon: true,
),
const SizedBox(height: 8),
TUISearchBar(
showBackIcon: true,
showTrailingIcon: true,
),
const SizedBox(height: 8),
TUISearchBar(
showBackIcon: false,
showTrailingIcon: true,
onChanged: (String value) {},
autofocus: true,
),
const SizedBox(height: 100),
],
),
Expand Down
24 changes: 11 additions & 13 deletions lib/components/checkbox_row/checkbox_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,40 @@ class TUICheckBoxRow extends StatefulWidget {
final String title;
final String description;
final bool backgroundDark;
final bool enableMixedState;
final TUICheckBoxRowState state;
final Function(TUICheckBoxRowState)? onChanged;

TUICheckBoxRow({
super.key,
const TUICheckBoxRow({
Key? key,
this.enableMixedState = false,
this.state = TUICheckBoxRowState.unchecked,
required this.title,
this.description = "",
this.onChanged,
this.backgroundDark = false,
}) {
if (state == TUICheckBoxRowState.mixed) {
enableMixedState = true;
}
}

late bool enableMixedState;
final TUICheckBoxRowState state;
final Function(TUICheckBoxRowState)? onChanged;
}) : super(key: key);

@override
State<StatefulWidget> createState() => _TUICheckBoxRowState();
}

class _TUICheckBoxRowState extends State<TUICheckBoxRow> {
TUICheckBoxRowState state = TUICheckBoxRowState.unchecked;
bool _enableMixedState = false;

@override
initState() {
super.initState();
state = widget.state;
if (state == TUICheckBoxRowState.mixed) {
_enableMixedState = true;
}
}

_setState() {
setState(() {
if (widget.enableMixedState == true) {
if (_enableMixedState == true) {
int rawValue = state.index;
state = TUICheckBoxRowState.getByValue((rawValue + 1) % 3);
} else {
Expand Down Expand Up @@ -195,7 +194,6 @@ enum TUICheckBoxRowState {
checked(2);

const TUICheckBoxRowState(this.value);

final num value;

static TUICheckBoxRowState getByValue(num i) {
Expand Down
13 changes: 8 additions & 5 deletions lib/components/email_field/email_field.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:tarka_ui/styles/text_style.dart';
import 'package:tarka_ui/styles/theme.dart';
import 'package:tarka_ui/styles/text_style.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';

class TUIEmailField extends StatefulWidget {
Expand All @@ -9,23 +9,25 @@ class TUIEmailField extends StatefulWidget {
final bool showSuffix;
final VoidCallback? onAdd;
final VoidCallback? onRemove;
final TextEditingController? controller;

const TUIEmailField({
super.key,
Key? key,
this.label = TUIEmailFieldLabel.to,
required this.emails,
this.showSuffix = false,
this.onAdd,
this.onRemove,
});
this.controller,
}) : super(key: key);

@override
State<StatefulWidget> createState() => _TUIEmailFieldState();
}

class _TUIEmailFieldState extends State<TUIEmailField> {
late List<String> _emails = [];
final TextEditingController _emailController = TextEditingController();
TextEditingController _emailController = TextEditingController();
final FocusNode _focusNode = FocusNode();
BorderSide borderSide = const BorderSide(
width: 2.0,
Expand All @@ -35,6 +37,7 @@ class _TUIEmailFieldState extends State<TUIEmailField> {
@override
void initState() {
super.initState();
_emailController = widget.controller ?? TextEditingController();
_emails = widget.emails;
_focusNode.addListener(onFocusChange);
_emailController.addListener(onTextChanged);
Expand Down Expand Up @@ -145,7 +148,7 @@ class _TUIEmailFieldState extends State<TUIEmailField> {
) {
int idx = _emails.indexOf(email);
return getChip(email, theme, idx);
}),
}).toList(),
],
),
TextField(
Expand Down
7 changes: 2 additions & 5 deletions lib/components/menu_item/menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class TUIMenuItem extends StatefulWidget {
final Function(TUIMenuItemState)? onRightTap;

const TUIMenuItem({
super.key,
Key? key,
required this.item,
this.backgroundDark = false,
this.onLeftTap,
this.onRightTap,
this.action,
});
}) : super(key: key);

@override
State<StatefulWidget> createState() => _TUIMenuItemState();
Expand Down Expand Up @@ -329,7 +329,6 @@ enum TUIMenuItemStyle {
both(3);

const TUIMenuItemStyle(this.value);

final num value;

static TUIMenuItemStyle getByValue(num i) {
Expand All @@ -344,7 +343,6 @@ enum TUIMenuItemState {
bothChecked(3);

const TUIMenuItemState(this.value);

final num value;

static TUIMenuItemState getByValue(num i) {
Expand All @@ -358,7 +356,6 @@ enum TUIMenuItemTapped {
none(3);

const TUIMenuItemTapped(this.value);

final num value;

static TUIMenuItemTapped getByValue(num i) {
Expand Down
123 changes: 123 additions & 0 deletions lib/components/search_bar/search_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:tarka_ui/styles/theme.dart';

class TUISearchBar extends StatefulWidget {
final bool showBackIcon;
final bool showTrailingIcon;
final String placeholder;
final Function()? onBackAction;
final Function()? onTrainlingButtonAction;
final Function(String)? onChanged;
final TextEditingController? textEditingController;
final bool autofocus;

const TUISearchBar({
super.key,
this.showBackIcon = true,
this.showTrailingIcon = false,
this.placeholder = "Search",
this.onBackAction,
this.onTrainlingButtonAction,
this.textEditingController,
this.onChanged,
this.autofocus = false,
});

@override
State<StatefulWidget> createState() => _TUISearchBarState();
}

class _TUISearchBarState extends State<TUISearchBar> {
TextEditingController _controller = TextEditingController();

@override
void initState() {
super.initState();
_controller = widget.textEditingController ?? TextEditingController();
}

@override
Widget build(BuildContext context) {
TUIThemeData theme = TUITheme.of(context);

return Container(
padding: const EdgeInsets.fromLTRB(4.0, 4.0, 4.0, 4.0),
width: MediaQuery.of(context).size.width,
height: 48.0,
decoration: BoxDecoration(
color: theme.colors.background,
borderRadius: const BorderRadius.all(
Radius.circular(75.0),
),
),
child: Row(
children: [
getPrefixIcon(theme),
Flexible(
child: TextField(
maxLines: 1,
controller: _controller,
style: theme.typography.body6,
cursorHeight: 16.0,
textAlign: TextAlign.start,
textAlignVertical: TextAlignVertical.top,
onChanged: (value) => widget.onChanged?.call(value),
autofocus: widget.autofocus,
decoration: InputDecoration(
hintText: widget.placeholder,
border: InputBorder.none,
isDense: true,
contentPadding: getContentPadding(),
),
),
),
getSuffixIcon(theme),
],
),
);
}

getContentPadding() {
EdgeInsets padding = EdgeInsets.zero;
if (!widget.showBackIcon) {
return padding.copyWith(left: 24.0);
}
return padding;
}

getSuffixIcon(TUIThemeData theme) {
if (widget.showTrailingIcon) {
return GestureDetector(
onTap: () {
_controller.text = "";
widget.onTrainlingButtonAction?.call();
},
child: Container(
padding: const EdgeInsets.all(8.0),
child: Icon(
FluentIcons.dismiss_24_filled,
color: theme.colors.onSurface,
),
),
);
}
return Container();
}

getPrefixIcon(TUIThemeData theme) {
if (widget.showBackIcon) {
return GestureDetector(
onTap: () => widget.onBackAction?.call(),
child: Container(
padding: const EdgeInsets.all(8.0),
child: Icon(
FluentIcons.chevron_left_24_filled,
color: theme.colors.onSurface,
),
),
);
}
return Container();
}
}
4 changes: 2 additions & 2 deletions lib/components/toggle_row/toggle_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class TUIToggleRow extends StatefulWidget {
final bool backgroundDark;

const TUIToggleRow({
super.key,
Key? key,
required this.title,
this.description = "",
this.icon,
required this.value,
this.onChanged,
this.backgroundDark = false,
});
}) : super(key: key);

@override
State<StatefulWidget> createState() => _TUIToggleRowState();
Expand Down

0 comments on commit 12dc14e

Please sign in to comment.