coffee_required 0.0.1 copy "coffee_required: ^0.0.1" to clipboard
coffee_required: ^0.0.1 copied to clipboard

A humorous debug-only guard that enforces coding hours, break reminders, and coffee breaks with sarcastic or corporate overlay messages.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:coffee_required/coffee_required.dart';

void main() {
  // 1. Initialize with your rules
  CoffeeRequired.init(
    config: const CoffeeConfig(
      enabled: true,
      mode: CoffeeMode.warnOnly, // We use warnOnly so we can see the wrapper in action
      minHour: 9, // Assuming it is before 9 or we can force a fail by setting set hour
      maxHour: 23,
      roastLevel: CoffeeRoastLevel.sarcastic,
      showOverlay: true,
      allowOverride: true,
      breakReminderMinutes: 1, // Short for demo
    ),
  );

  // 2. Check the gate!
  // This will log a warning or throw exception if blockApp.
  // Since we used warnOnly, it will log and schedule an overlay.
  // Note: For overlay to appear, we need to pass the navigatorKey below.
  CoffeeRequired.ensure();

  // 3. Start break reminders (optional)
  CoffeeRequired.remindBreaks();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Coffee Required Demo',
      // 4. IMPORTANT: Pass the navigator key for overlays to work!
      navigatorKey: CoffeeRequired.navigatorKey,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.brown),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Coffee Guard Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                // Simulate manually drinking coffee
                CoffeeRequired.iHadCoffee();
                ScaffoldMessenger.of(context).showSnackBar(
                  const SnackBar(content: Text("Manual override activated!")),
                );
              },
              child: const Text("I had coffee manually"),
            ),
             const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                 // Reset override
                 CoffeeRequired.resetOverride();
                 ScaffoldMessenger.of(context).showSnackBar(
                  const SnackBar(content: Text("Override reset. You are vulnerable again.")),
                );
              },
              child: const Text("Reset Override"),
            ),
             const SizedBox(height: 10),
             const Text("Wait 1 minute for break reminder..."),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
2
likes
160
points
80
downloads

Publisher

unverified uploader

Weekly Downloads

A humorous debug-only guard that enforces coding hours, break reminders, and coffee breaks with sarcastic or corporate overlay messages.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on coffee_required