-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for accessibility tools & refactor button
- Loading branch information
Showing
8 changed files
with
251 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,6 @@ class Application extends StatelessWidget { | |
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
const ExampleWidget(), | ||
FButton( | ||
text: 'Hi', | ||
onPress: () {}, | ||
), | ||
], | ||
), | ||
), | ||
|
@@ -41,176 +37,39 @@ class ExampleWidget extends StatefulWidget { | |
} | ||
|
||
class _ExampleWidgetState extends State<ExampleWidget> { | ||
late WidgetStatesController controller; | ||
late TextEditingController textController; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
controller = WidgetStatesController(); | ||
textController = TextEditingController()..addListener(() {}); | ||
} | ||
|
||
Widget _dialog(BuildContext context) { | ||
final style = context.theme.cardStyle; | ||
final contentStyle = style.content; | ||
final typography = context.theme.typography; | ||
final effectivePadding = | ||
MediaQuery.viewInsetsOf(context) + const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0); | ||
|
||
final child = Align( | ||
child: DefaultTextStyle( | ||
style: context.theme.typography.toTextStyle( | ||
fontSize: typography.base, | ||
color: context.theme.colorScheme.foreground, | ||
), | ||
child: ConstrainedBox( | ||
constraints: const BoxConstraints(minWidth: 280.0), | ||
child: DecoratedBox( | ||
decoration: style.decoration, | ||
child: Padding( | ||
padding: style.content.padding, | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
Text('Are you absolutely sure?', style: contentStyle.title.scale(typography)), | ||
SizedBox( | ||
height: 10, | ||
), | ||
Text( | ||
'This action cannot be undone. This will permanently delete your account and remove your data from our servers.', | ||
style: contentStyle.subtitle.scale(typography), textAlign: TextAlign.center,), | ||
SizedBox( | ||
height: 18, | ||
), | ||
LayoutBuilder( | ||
builder: (context, constraints) { | ||
// Get the width of the screen | ||
final screenWidth = MediaQuery.sizeOf(context).width; | ||
|
||
// Calculate the combined width of the buttons | ||
final buttonWidth = constraints.maxWidth; | ||
|
||
print(screenWidth); | ||
print(buttonWidth); | ||
|
||
// If the combined width of the buttons exceeds the screen width, place them in a Column | ||
if (true) { | ||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 7.0), | ||
child: FButton(text: 'Continue', onPress: () {}), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 7.0), | ||
child: FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () {}), | ||
), | ||
], | ||
); | ||
} else { | ||
// Otherwise, place them in a Row | ||
return Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Expanded( | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 7.0), | ||
child: FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () {}), | ||
), | ||
), | ||
Expanded( | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 7.0), | ||
child: FButton(text: 'Continue', onPress: () {}), | ||
), | ||
), | ||
], | ||
); | ||
} | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
)), | ||
), | ||
); | ||
|
||
return AnimatedPadding( | ||
padding: effectivePadding, | ||
duration: const Duration(milliseconds: 100), | ||
curve: Curves.decelerate, | ||
child: MediaQuery.removeViewInsets( | ||
removeLeft: true, | ||
removeTop: true, | ||
removeRight: true, | ||
removeBottom: true, | ||
context: context, | ||
child: child, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
showAdaptiveDialog( | ||
context: context, | ||
builder: (context) { | ||
final style = context.theme.cardStyle; | ||
return _dialog(context); | ||
|
||
// return AlertDialog() | ||
// return Dialog(child: Column( | ||
// crossAxisAlignment: CrossAxisAlignment.start, | ||
// children: [ | ||
// Text('Are you absolutely sure?', style: contentStyle.title.scale(typography)), | ||
// Text('This action cannot be undone. This will permanently delete your account and remove your data from our servers.', style: contentStyle.subtitle.scale(typography)), | ||
// Row( | ||
// children: [ | ||
// FButton(design: FButtonVariant.secondary, text: 'Cancel', onPress: () {}), | ||
// FButton(text: 'Continue', onPress: () {}), | ||
// ], | ||
// ) | ||
// ], | ||
// ),); | ||
}, | ||
); | ||
}); | ||
return Padding( | ||
Widget build(BuildContext context) => Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Column( | ||
children: [ | ||
// FCard(title: 'Email'), | ||
FTextField( | ||
// enabled: false, | ||
labelText: 'Email', | ||
hintText: '[email protected]', | ||
helpText: 'This is your public display name.', | ||
// errorText: 'Error', | ||
// statesController: controller, | ||
controller: textController, | ||
FButton( | ||
design: FButtonVariant.destructive, | ||
text: 'Delete?', | ||
onPress: () => showAdaptiveDialog( | ||
context: context, | ||
builder: (context) { | ||
final style = context.theme.cardStyle; | ||
return FDialog( | ||
title: 'Are you absolutely sure?', | ||
subtitle: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.', | ||
actions: [ | ||
FButton(text: 'Continue', onPress: () {}), | ||
FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () { | ||
Navigator.of(context).pop(); | ||
}), | ||
], | ||
); | ||
// return _dialog(context); | ||
}, | ||
), | ||
), | ||
// const TextField( | ||
// // enabled: false, | ||
// decoration: InputDecoration( | ||
// labelText: 'Material TextField', | ||
// hintText: 'Email', | ||
// errorText: 'Error text', | ||
// ), | ||
// ), | ||
], | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
super.dispose(); | ||
controller.dispose(); | ||
textController.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.