Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shafayathossain/4d34899844753e223e99de4eac9fd905 to your computer and use it in GitHub Desktop.

Select an option

Save shafayathossain/4d34899844753e223e99de4eac9fd905 to your computer and use it in GitHub Desktop.
Flutter Preview - Example Widget
class SimpleWidget extends StatelessWidget {
final String text;
final IconData icon;
const SimpleWidget({
super.key,
required this.text,
required this.icon,
});
@override
Widget build(BuildContext context) {
final isRTL = Directionality.of(context) == TextDirection.rtl;
return LayoutBuilder(
builder: (context, constraints) {
final isWide = constraints.maxWidth > 400;
return Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Flex(
direction: isWide ? Axis.horizontal : Axis.vertical,
mainAxisSize: isWide ? MainAxisSize.max : MainAxisSize.min,
textDirection: isRTL ? TextDirection.rtl : TextDirection.ltr,
children: [
Icon(icon, size: isWide ? 32 : 24),
SizedBox(width: 8, height: 8),
Text(
text,
style: Theme.of(context).textTheme.titleSmall,
textAlign: TextAlign.center,
textDirection: isRTL ? TextDirection.rtl : TextDirection.ltr,
),
],
),
),
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment