Skip to content

Commit

Permalink
implementing sbb input trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
VanHoangTran committed Dec 15, 2023
1 parent ed0880a commit 33adff1
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 1 deletion.
5 changes: 5 additions & 0 deletions example/lib/native_app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:animations/animations.dart';
import 'package:design_system_flutter/design_system_flutter.dart';
import 'pages/input_trigger_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -176,6 +177,10 @@ class MyApp extends StatelessWidget {
_DemoEntry(
'Status',
StatusPage(),
),
_DemoEntry(
'Input Trigger',
InputTriggerPage(),
isLastElement: true,
),
],
Expand Down
157 changes: 157 additions & 0 deletions example/lib/pages/input_trigger_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import 'package:design_system_flutter/design_system_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../native_app.dart';

class InputTriggerPage extends StatefulWidget {
@override
State<InputTriggerPage> createState() => _PickerPageState();
}

class _PickerPageState extends State<InputTriggerPage> {
DateTime? selectedDate;

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(
vertical: sbbDefaultSpacing,
horizontal: sbbDefaultSpacing * 0.5,
),
child: Column(
children: <Widget>[
ThemeModeSegmentedButton(),
const SizedBox(
height: sbbDefaultSpacing,
),
SBBGroup(
child: Column(
children: [
SBBInputTrigger(
maxLines: 1,
value: inputValue,
labelText: labelValue,
hintText: hintValue,
errorText: errorValue,
onPressed: () {
showSBBModalSheet(
context: context,
title: 'Date',
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SBBDatePicker(onDateChanged: (DateTime date) {
setState(() {
selectedDate = date;
valueController.text = date.toIso8601String();
});
}),
],
),
);
},
prefixIcon: showPrefixIcon ? SBBIcons.dog_small : null,
suffixIcon: showSuffixIcon
? SBBIcons.circle_information_small_small
: null,
onSuffixPressed: () {},
enabled: enabled,
),
],
),
),
const SizedBox(
height: sbbDefaultSpacing,
),
SBBGroup(
child: Column(
children: [
SBBTextField(
controller: labelController,
labelText: 'Label',
),
SBBTextField(
controller: hintController,
labelText: 'Hint',
),
SBBTextField(
controller: valueController,
labelText: 'Value',
),
SBBTextField(
controller: errorController,
labelText: 'Error',
),
SBBSwitchListItem(
title: 'Enabled',
value: enabled,
onChanged: (enabled) {
setState(() {
this.enabled = enabled;
});
},
),
SBBSwitchListItem(
title: 'Prefix Icon',
value: showPrefixIcon,
onChanged: (enabled) {
setState(() {
this.showPrefixIcon = enabled;
});
},
),
SBBSwitchListItem(
title: 'Suffix Icon',
value: showSuffixIcon,
onChanged: (enabled) {
setState(() {
this.showSuffixIcon = enabled;
});
},
),
],
),
),
],
),
);
}

bool enabled = true;
bool showPrefixIcon = true;
bool showSuffixIcon = true;
String inputValue = '';
String labelValue = '';
String hintValue = '';
String errorValue = '';
final valueController = TextEditingController();
final labelController = TextEditingController();
final hintController = TextEditingController();
final errorController = TextEditingController();

@override
void initState() {
super.initState();
valueController.addListener(() {
setState(() {
inputValue = valueController.text;
});
});
labelController.addListener(() {
setState(() {
labelValue = labelController.text;
});
});
hintController.addListener(() {
setState(() {
hintValue = hintController.text;
});
});
errorController.addListener(() {
setState(() {
errorValue = errorController.text;
});
});
}
}
1 change: 1 addition & 0 deletions lib/design_system_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export 'src/dropdown/sbb_dropdown.dart';
export 'src/group/sbb_group.dart';
export 'src/header/sbb_header.dart';
export 'src/header/sbb_web_header.dart';
export 'src/input_trigger/sbb_input_trigger.dart';
export 'src/link/sbb_link_text.dart';
export 'src/list_header/sbb_list_header.dart';
export 'src/list_item/sbb_list_item.dart';
Expand Down
Loading

0 comments on commit 33adff1

Please sign in to comment.