Sunday, 18 August 2019

Small and extensible logger which prints beautiful logs with flutter



Logger

Small, easy to use and extensible logger which prints beautiful logs.
Inspired by logger for Android.

Getting Started

Just create an instance of Logger and start logging:
var logger = Logger();

logger.d("Logger is working!");
Dart
Instead of a string message, you can also pass other objects like ListMap or Set.

Output



Log Console

If you are creating a Flutter app, you can use the logger_flutter extension. Shake the phone to show an on device console.

Documentation

Log level

You can log with different levels:
logger.v("Verbose log");

logger.d("Debug log");

logger.i("Info log");

logger.w("Warning log");

logger.e("Error log");

logger.wtf("What a terrible failure log");
Dart
To show only specific log levels, you can set:
Logger.level = Level.warning;
Dart
This hides all verbosedebug and info log events.

Options

When creating a logger, you can pass some options:
var logger = Logger(
  filter: null, // Use the default LogFilter (-> only log in debug mode)
  printer: PrettyPrinter(), // Use the PrettyPrinter to format and print log
  output: null, // Use the default LogOutput (-> send everything to console)
);
Dart
If you use the PrettyPrinter, there are more options:
var logger = Logger(
  printer: PrettyPrinter(
    methodCount: 2, // number of method calls to be displayed
    errorMethodCount: 8, // number of method calls if stacktrace is provided
    lineLength: 120, // width of the output
    colors: true, // Colorful log messages
    printEmojis: true, // Print an emoji for each log message
    printTime: false // Should each log print contain a timestamp
  ),
)
Dart

LogFilter

The LogFilter decides which log events should be shown and which don't.

The default implementation (DebugFilter) shows all logs with level >= Logger.level while in debug mode. In release mode all logs are omitted.
You can create your own LogFilter like this:
class MyFilter extends LogFilter {
  @override
  bool shouldLog(LogEvent event) {
    return true;
  }
}
Dart
This will show all logs even in release mode. (NOT a good idea)

LogPrinter

The LogPrinter creates and formats the output, which is then sent to the LogOutput.

You can implement your own LogPrinter. This gives you maximum flexibility.
A very basic printer could look like this:
class MyPrinter extends LogPrinter {
  @override
  void log(LogEvent event) {
    println(event.message);
  }
}
Dart
Important: Every implementation has to send its output using the println() method.
If you created a cool LogPrinter which might be helpful to others, feel free to open a pull request. :)

LogOutput

LogOutput sends the log lines to the desired destination.

The default implementation (ConsoleOutput) send every line to the system console.
class ConsoleOutput extends LogOutput {
  @override
  void output(OutputEvent event) {
    for (var line in event.lines) {
      print(line);
    }
  }
}
Dart
Possible future LogOutputs could send to a file, firebase or to Logcat. Feel free to open pull requests.

logger_flutter extension

The logger_flutter package is an extension for logger. You can add it to any Flutter app. Just shake the phone to show the console.
  1. Add logger_flutter to your pubspec.yaml
  2. Add the following code into your widget tree
LogConsoleOnShake(
  child: Container() // Your widgets
),
Dart
More documentation coming soon.

GitHub

Small, easy to use and extensible logger which prints beautiful logs. — Read More
Latest commit to the master branch on 7-24-2019
Download as zip

Flutter animation interactive guide



flutter_animation_explorer

Flutter animation interactive guide.


  • Curves visualizer
  • Animated widgets demo :
    • AnimatedContainer
    • AnimatedAlign
    • AnimatedPositioned
    • AnimatedOpacity
    • AnimatedDefaultTextStyle
  • Staggered animation explorer

web

You need to be on Flutter master branch to run/build for web, and follow this instructions
flutter run -d chrome
Bash

mac os

You need to be on Flutter master branch to run/build for web, and follow this instructions
flutter run -d macos -t lib/main_desktop.dart
Bash

GitHub

📈 flutter animation explorer — Read More
Latest commit to the master branch on 8-17-2019
Download as zip

Friday, 16 August 2019

A Food app built with Flutter



Flutter-Food-app

A Food app built with Flutter.

Features

- Signup with firebase
- Login with firebase

Run project

- Create firebase project & add `google-services.json` file in `android/app` folder.

GitHub

Flutter food app. — Read More
Latest commit to the master branch on 8-15-2019
Download as zip

A beautiful BMI calculator app with Flutter


Flutter BMI Calculator

A beautiful BMI calculator app. Developed using Flutter.


Library Used

  • Material
  • Dart Math
  • FontAwesome

Widgets / Classes Used

  • StatefulWidget
  • Scaffold
  • AppBar
  • Text
  • TextStyle
  • SafeArea
  • Padding
  • Column
  • Row
  • Colors
  • Color
  • Expanded
  • FlatButton
  • Center
  • Icon
  • Alert
  • AlertStyle
  • DialogButton

Concepts Used

  • Object Oriented Programming
  • Class
  • Property
  • Constructor
  • Method
  • Abstraction
  • Inheritance
  • Encapsulation
  • Polymorphism
  • List
  • Conditional

GitHub

A beautiful BMI calculator app. Developed using Flutter. — Read More
Latest commit to the master branch on 8-15-2019
Download as zip

A radio button widget for flutter that supports custom builders


custom_radio

An animatable radio button that can be customized to the max.
I found it strange that flutter only provides two radio widgets: Radio and RadioListTile The main issue with these widgets is that both of them force the use of the default Android leading animated circular icon. This widget leaves everything up to the user by allowing them to provide their own builder function. On top of that, an animations builder can also be provided. This gets passed a parent animation controller with which the user can then use to create a list of animations that can animate the widgets transition between states.

Installation

Simply add custom_radio: ^0.1.2 as a dependancy in your pubspec.yaml file.
Then import 'package:custom_radio/custom_radio.dart'; wherever you need it.

Examples



If only one animation type is required then it can be specified to enable stronger typing.
CustomRadio<String, double>(
  value: 'First',
  groupValue: widget.radioValue,
  duration: Duration(milliseconds: 500),
  animsBuilder: (AnimationController controller) => [
    CurvedAnimation(
      parent: controller,
      curve: Curves.easeInOut
    )
  ],
  builder: (BuildContext context, List<double> animValues, Function updateState, String value) {
    final alpha = (animValues[0] * 255).toInt();
    return GestureDetector(
      onTap: () {
        setState(() {
          widget.radioValue = value;
        });
      },
      child: Container(
        padding: EdgeInsets.all(32.0),
        margin: EdgeInsets.all(12.0),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: Theme.of(context).primaryColor.withAlpha(alpha),
          border: Border.all(
            color: Theme.of(context).primaryColor.withAlpha(255 - alpha),
            width: 4.0,
          )
        ),
        child: Text(
          value,
          style: Theme.of(context).textTheme.body1.copyWith(fontSize: 24.0),
        )
      )
    );
  }
)
But any combination of animation types are supported.
CustomRadio<String, dynamic>(
  value: 'First',
  groupValue: widget.radioValue,
  animsBuilder: (AnimationController controller) => [
    CurvedAnimation(
      parent: controller,
      curve: Curves.easeInOut
    ),
    ColorTween(
      begin: Colors.white,
      end: Colors.deepPurple
    ).animate(controller),
    ColorTween(
      begin: Colors.deepPurple,
      end: Colors.white
    ).animate(controller),
  ],
  builder: (BuildContext context, List<dynamic> animValues, Function updateState, String value) {
    return GestureDetector(
      onTap: () {
        setState(() {
          widget.radioValue = value;
        });
      },
      child: Container(
        alignment: Alignment.center,
        margin: EdgeInsets.all(18.0),
        padding: EdgeInsets.all(32.0 + animValues[0] * 12.0),
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: animValues[1],
          border: Border.all(
            color: animValues[2],
            width: 2.0
          )
        ),
        child: Text(
          value,
          style: Theme.of(context).textTheme.body1.copyWith(
            fontSize: 20.0,
            color: animValues[2]
          ),
        )
      )
    );
  },
)

GitHub

A radio button widget for flutter that supports custom builders and a variable number of animations. — Read More
Latest commit to the master branch on 8-15-2019
Download as zip