Skip to content

Commit

Permalink
✨ Initial addition of classic admonitions
Browse files Browse the repository at this point in the history
  • Loading branch information
iqfareez committed Jun 6, 2022
1 parent 609125e commit 63b20e4
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
23 changes: 23 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ class MyHomePage extends StatelessWidget {
child: const Text('Action 2'))
],
),
Text(
'Classic Admonitions',
style: Theme.of(context).textTheme.headline6,
),
const ClassicAdmonition.note(
text: '(Note) You might read this, you might not.',
),
const ClassicAdmonition.tip(
text: '(Tip) You want to read this.',
),
const ClassicAdmonition.info(
text: '(Info/Important) You should read this.',
),
const ClassicAdmonition.caution(
text: '(Caution) I hope you read this.',
),
const ClassicAdmonition.danger(
text: '(Danger) You need to read this.',
),
const ClassicAdmonition(
text:
'(Raw) Background colour is defaulted to your app primary colour.',
),
],
),
),
Expand Down
8 changes: 8 additions & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
8 changes: 8 additions & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
1 change: 1 addition & 0 deletions lib/admonitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ library admonitions;

export 'src/solid.dart';
export 'src/pastel.dart';
export 'src/classic.dart';
139 changes: 139 additions & 0 deletions lib/src/classic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class ClassicAdmonition extends StatelessWidget {
/// Classic admonitions (solid line on the left, pastel colour on the right)
const ClassicAdmonition(
{Key? key,
this.child,
this.text,
this.color = Colors.blue,
this.icon,
this.opacity = .3,
this.actions,
this.primaryColor})
: assert(child == null || text == null,
'Either child or text is allowed to exist'),
super(key: key);

const ClassicAdmonition.note({
Key? key,
this.child,
this.text,
this.color = const Color(0xffebedf0),
this.icon = const FaIcon(FontAwesomeIcons.circleInfo),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);

const ClassicAdmonition.tip({
Key? key,
this.child,
this.text,
this.color = const Color(0xff00a400),
this.icon = const FaIcon(FontAwesomeIcons.lightbulb),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);

const ClassicAdmonition.info({
Key? key,
this.child,
this.text,
this.color = const Color(0xff54c7ec),
this.icon = const FaIcon(FontAwesomeIcons.circleExclamation),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);
const ClassicAdmonition.caution({
Key? key,
this.child,
this.text,
this.color = const Color(0xffffba00),
this.icon = const FaIcon(FontAwesomeIcons.triangleExclamation),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);
const ClassicAdmonition.danger({
Key? key,
this.child,
this.text,
this.color = const Color(0xfffa383e),
this.icon = const FaIcon(FontAwesomeIcons.fire),
this.opacity = .3,
this.actions,
this.primaryColor,
}) : super(key: key);

final String? text;

final Widget? child;

final Color? color;

final Widget? icon;

final double opacity;

final Color? primaryColor;

final List<Widget>? actions;

@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(4),
child: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: Stack(children: [
Positioned.fromRect(
rect: Rect.fromLTRB(0, 0, 8, 400),
child: Container(
color: color,
// constraints: BoxConstraints.expand(),
),
),
Container(
padding: const EdgeInsets.all(14),
color:
(color ?? Theme.of(context).primaryColor).withOpacity(opacity),
child: Column(
children: [
Row(
children: [
if (icon != null) ...[
IconTheme(
data: IconThemeData(
color: primaryColor ??
Theme.of(context).iconTheme.color,
size: 18),
child: icon!),
const SizedBox(width: 10)
],
if (text != null)
DefaultTextStyle(
style: TextStyle(
color: primaryColor ??
Theme.of(context).textTheme.bodyText1!.color),
child: Flexible(child: Text(text!)))
else
child!
],
),
if (actions != null)
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: actions!,
)
],
),
),
]),
),
);
}
}

0 comments on commit 63b20e4

Please sign in to comment.