Skip to content

Instantly share code, notes, and snippets.

bool confirm = await showDialog<bool>(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Are you sure?'),
content: const Text('This action cannot be undone.'),
actions: [
TextButton(
child: const Text('Cancel'),
onPressed: (){
/// Get the color from a gradient at a specific position
/// Position should be between 0 and 1
extension ColorGetter on Gradient {
Color? colorAtPosition({
required double position,
}) {
List<double> _stops = stops ?? List.generate(colors.length, (index) => index * (1 / (colors.length-1)));
for (var stop = 0; stop < _stops.length - 1; stop++) {
class FirstTimeView extends HookWidget {
@override
Widget build(BuildContext context) {
TickerProvider tickerProvider = useSingleTickerProvider();
return ViewModelBuilder<FirstTimeViewModel>.reactive(
viewModelBuilder: () => FirstTimeViewModel(tickerProvider),
builder: (context, model, child) {
return Scaffold(
appBar: AppBar(
/// Get the color from a gradient at a specific position
Color? colorAlongGradient({
required List<Color> colors,
List<double>? stops,
required double position,
}) {
stops ??= List.generate(colors.length, (index) => index * (1 / (colors.length-1)));
for (var s = 0; s < stops.length - 1; s++) {
final leftStop = stops[s], rightStop = stops[s + 1];
@jtmuller5
jtmuller5 / tabBar.dart
Created September 10, 2021 19:57
Basic TabBar
DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(
bottom: const TabBar(
tabs: [
Tab(icon: Icon(Icons.home),),
Tab(icon: Icon(Icons.whatshot),),
Tab(icon: Icon(Icons.person),),
Tab(icon: Icon(Icons.menu),),
@jtmuller5
jtmuller5 / ask_confirmation.dart
Created May 22, 2021 23:40
Ask the user to approve or cancel an action in a pop-up
Future<bool> askConfirmation({
required BuildContext context,
required String title,
String yes = 'Continue',
String no = 'Cancel',
}) async {
return await showDialog(
context: context,
builder: (context) {
return AlertDialog(
GestureDetector(
onTap: () {
model.setInteraction(false);
},
behavior: HitTestBehavior.deferToChild,
child: InteractiveViewer(
panEnabled: false,
boundaryMargin: EdgeInsets.all(80),
onInteractionStart: (details) {
model.setInteraction(true);
class BodyPainter extends CustomPainter {
final BuildContext context;
final BodySelectorViewModel model;
BodyPainter({
required this.context,
required this.model,
});
@override
class BodyCanvas extends ViewModelWidget<BodySelectorViewModel> {
@override
Widget build(BuildContext context, BodySelectorViewModel model) {
return CanvasTouchDetector(
builder: (context) => CustomPaint(
painter: BodyPainter(
context: context,
model: model,
),
),
Future<void> loadSvgImage({required bool back, required String svgImage}) async {
String generalString = await rootBundle.loadString(svgImage);
XmlDocument document = XmlDocument.parse(generalString);
final paths = document.findAllElements('path');
paths.forEach((element) {
String partName = element.getAttribute('id').toString();