flutter_stash 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Flutter Stash pull-requests-badge

Created by Alexandre Bolot on 16/06/2019

Table of contents #

Project objectives #

I created this Flutter-package to gather Widgets, Views and methods that I frequently use between projects.

The final objective is to be able to share those classes, accept calsses from others (via pull-requests), in order to reduce code duplicates, endless copy-pasting between previous and new projects, and a much better maintenance.

Content #

Flutter content #

SplashScreen #

This widget is used as a dynamic front page before the home page is displayed. It allows you to perform synchronous and asynchronous tasks before automatically navigation to the home page.

The following example shows how to build a SplashScreen for an app called MyApp, perform basic asynchronous tasks (loading user preferences, obtaining a user token, etc), and then navigating to another widget page called HomePage.

//Example :
SplashScreen(
  title: 'Welcome to MyApp',
  nextRouteName: '/HomePage',
  loadFunctions: [
    () => print('started loading stuff'),
    () async => await loadUserPreferences(),
    () async => await getUserTokenFromServer(),
    () => print('ready to go, token : ${user.token}')
  ],
);

_____________________________________________

SplashScreen(
  title: 'Welcome to MyApp',
  nextRoute: MaterialPageRoute(builder: (context)=> HomePage()),
  loadFunctions = [
    () => print('started loading stuff'),
    () async => await loadUserPreferences(),
    () async => await getUserTokenFromServer(),
    () => print('ready to go, token : ${user.token}')
  ],
);

BubbleLoader #

This stateful widget is used as a custom CircularProgressIndicator

It's composed of 12 bubbles with decreasing radius, forming a circle. They simply turn in rounds until this widget is disposed.

It has only a default constructor so no parameters are needed. Yet, I recommend to always use it in a container with a well defined height or width.

//Example :

Container(
  width: double.infinity,
  height: 250.0,
  child: Center(
    child: Container(
     child: loader,
    ),
  ),
)

TooltipText #

Simple widget used to add a Tooltip to a Text widget

This allows the user to display a tooltip message when applying a long-press on the displayed text widget.

// Example :
TooltipText(
  text: 'This is the main displayed text',
  tooltip: 'Useful information',
);

_____________________________________________

TooltipText(
  text: 'This is the main displayed text',
  tooltip: 'Useful information',
  textAlign: TextAlign.center,
  style: TextStyle(
    fontsize: 18.0,
    fontWeight: FontWeight.bold,
  ),
);

Shared #

The shared.dart file gathers methods for global use across your projet.

// Returns the adequate text color to contrast
// with a given [background] Color
Color contrastOf(Color background)
// Formats a given [string] to used a 'sentence' format
// 
// UPPER CASE PHRASE -> Upper case phrase
// lower case phrase -> Lower case phrase
// Mixed CASE phrase -> Mixed case phrase
String toFirstUpper(String string)
// Used as a simplified reducer method
//
// Useful to simplify chained calls :
// myItems.map((item) => item.price).reduce(sum);

double sum(double a, double b)

Live Templates #

On this package's github page I also share Live Templates, which are not directly code, but can be used as code-snippets to create code skelettons faster.

They can be used by IDEs, for example JetBrains IDEs such as Android Studio or IntelliJ.

To add them, go to Settings > Editor > Live Templates

doc #

Creates a Dart documentation pattern, link here

/// <br>
/// Returns the [n] first characters of a given [string]
///
/// * [n] - Number of characters to return
/// * [string] - String value to extract the characters from
///
String extract(int n, String string){
    return string.substring(0, n);
}

model #

Creates a new model Class with useful methods link here

  • MyClass.fromMap(Map map) allows to create an instance from JSON
  • Map toMap() allows to parse this class as JSON

testclass #

Allows to easily create a new test class. Nothing more to say, this is not the most useful live template... link here


view #

Most likely the Live Template I use the most, even more when starting a new Flutter Application !

Creates a new flutter page view link here

The name given to the Widget will automatically fill :

  • routeName: used for easier access from Named-Routes navigation
  • title: text displayed as title of this view (in the appbar)

By default a page view displays a Scaffold containing a centered text, with the page's name in it.

Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(title: Text(widget.title)),
    body: Container (
      child : Center (
        child : Text(widget.title),
      ),
    ),
  );
}

[0.0.1] - First release !

  • This is my first release (every), still needs a proper README

[0.0.2] - Fixing an assertion error

  • Something went wrong with SplashScreen's constructor assertions. Added temporary fix :)

[0.0.3] - Fixing loop in BubbleLoader

  • On some occasions BubbleLoader created infinite loops... Fixed that :)

[1.0.0] - Paperwork-day

  • Upgrading README.md
  • Upgrading some documentation

[1.0.1] - Paperwork-day

  • Adding simple example for SplashScreen, BubbleLoader and TooltipText

example/example.dart

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    String applicationName = 'Money Tracker';

    buildSplashScreen() => SplashScreen(
          title: applicationName,
          nextRouteName: HomePage.routeName,
          loadFunctions: [
            () => print('hey there, I reached the SplashScreen'),
            // wait to simulate real async call
            () async => await Future.delayed(Duration(seconds: 5)),
            () => print("hey there, I'me leaving the SplashScreen"),
          ],
          nextRoute: MaterialPageRoute(builder: (context) => HomePage()),
        );

    return MaterialApp(
      title: applicationName,
      debugShowCheckedModeBanner: false,
      routes: {
        '/': (context) => buildSplashScreen(),
        SplashScreen.routeName: (context) => buildSplashScreen(),
        HomePage.routeName: (context) => HomePage(),
      },
    );
  }
}

class HomePage extends StatefulWidget {
  /// Use this for easier access from Named-Routes navigation
  static const String routeName = "/HomePage";

  /// Text displayed as title of this view (in the appbar)
  /// Default is empty string
  final String title;

  const HomePage({this.title = 'HomePage'});

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Container(
        child: Center(
          child: TooltipText(
            text: widget.title,
            tooltip: 'This is a tooltip',
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_stash: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_stash/flutter_stash.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/src/bubble_loader.dart. (-0.50 points)

Analysis of lib/src/bubble_loader.dart reported 1 hint:

line 32 col 7: This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: BubbleLoader.controller

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test