Toast Flutter Equinox

Toast Flutter Equinox

main.dart

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

import 'toast.dart';

void main() => runApp(new Myapp());

class Myapp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return EquinoxApp(
      title: 'Flutter Demo',
      theme: EqThemes.defaultLightTheme,
      home: ToastShowcase(),
    );
  }
}

pubspec.yaml

name: qtest
description: A new Flutter application.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  separated_column:
  stylist:
  equinox:

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

interactive_playground.dart

import 'package:equinox/equinox.dart';
import 'package:flutter/material.dart';
import 'package:qtest/utils.dart';

class BoolTyped {
  bool value;

  BoolTyped(this.value);
}

class EnumTyped<T> {
  T value;
  List<T> values;

  EnumTyped(this.value, this.values);
}

class InteractivePlayground extends StatefulWidget {
  final Widget Function(StyleData theme, Map<String, dynamic> data) builder;
  final Map<String, dynamic> data;

  const InteractivePlayground({Key key, this.builder, this.data})
      : super(key: key);
  @override
  _InteractivePlaygroundState createState() => _InteractivePlaygroundState();
}

class _InteractivePlaygroundState extends State<InteractivePlayground> {
  Map<String, dynamic> dataCopy;

  @override
  void initState() {
    dataCopy = widget.data;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final style = StaticStyle.of(context);
    var items = <Widget>[];

    for (final String key in dataCopy.keys) {
      final dynamic data = dataCopy[key];
      final String description = normalize(key);

      if (data is BoolTyped) {
        items.add(
          EqCheckbox(
            value: data.value,
            onChanged: (v) => setState(() => dataCopy[key].value = v),
            description: description,
            descriptionPosition: EqPositioning.right,
          ),
        );
      } else if (data is EnumTyped) {
        items.add(EqSelect(
          hint: description,
          items: data.values
              .map(
                (value) => EqSelectItem(
                  title: enumToString(value),
                  value: value,
                ),
              )
              .toList(),
          onSelect: (v) => setState(() => dataCopy[key].value = v),
          label: description,
          selectedIndex: data.values.indexOf(data.value),
        ));
      }
      items.add(SizedBox(height: 16.0));
    }

    items.add(
      widget.builder(
        style.style,
        dataCopy.map(
          (k, v) => MapEntry(k, v.value),
        ),
      ),
    );

    return EqCard(
      statusAppearance: EqCardStatusAppearance.none,
      header: Text('Interactive playground'),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: items,
      ),
    );
  }
}

showcase_state.dart

import 'package:equinox/equinox.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class ShowcaseWidgetData {
  final String title;
  final Widget Function() builder;
  final bool override;

  ShowcaseWidgetData({
    this.title,
    this.builder,
    this.override = false,
  });
}

abstract class ShowcaseState<T extends StatefulWidget> extends State<T> {
  List<ShowcaseWidgetData> get showcases;
  String get showcaseName;
  Widget playgroundBuilder();

  List<Widget> get children {
    var items = <Widget>[];

    showcases.forEach((showcase) {
      items.add(
        showcase.override
            ? showcase.builder()
            : EqCard(
                statusAppearance: EqCardStatusAppearance.none,
                header: Text(showcase.title),
                child: showcase.builder(),
              ),
      );
      items.add(SizedBox(height: 16.0));
    });

    items.add(playgroundBuilder());
    return items;
  }

  @override
  Widget build(BuildContext context) {
    return EqLayout(
      appBar: EqAppBar(
        title: 'Showcase',
        subtitle: showcaseName,
        centerTitle: true,
        actions: [
          EqIconButton(
            icon: EvaIcons.sunOutline,
            appearance: EqWidgetAppearance.ghost,
          ),
        ],
      ),
      child: ListView(
        padding: const EdgeInsets.all(16.0),
        children: children,
      ),
    );
  }
}

toast.dart

import 'package:equinox/equinox.dart';
import 'package:flutter/material.dart';
import 'package:separated_column/separated_column.dart';

import 'interactive_playground.dart';
import 'showcase_state.dart';
import 'utils.dart';

class ToastShowcase extends StatefulWidget {
  @override
  _ToastShowcaseState createState() => _ToastShowcaseState();
}

class _ToastShowcaseState extends ShowcaseState<ToastShowcase> {
  @override
  Widget playgroundBuilder() => InteractivePlayground(
    data: {
      'subtitle': BoolTyped(true),
      'icon': BoolTyped(true),
      'status': EnumTyped(EqWidgetStatus.success, EqWidgetStatus.values),
      'shape': EnumTyped(EqWidgetShape.semiRound, EqWidgetShape.values),
    },
    builder: (_, data) {
      return SizedBox(
        width: double.infinity,
        child: EqButton(
          status: data['status'],
          shape: data['shape'],
          label: Text('Show toast'),
          onTap: () => showToast(
            EqToast(
              message: 'A message',
              subtitle: data['subtitle'] ? 'And a subtitle' : null,
              icon: data['icon'] ? EvaIcons.star : null,
              status: data['status'],
              shape: data['shape'],
              duration: Duration(seconds: 5),
            ),
          ),
        ),
      );
    },
  );

  @override
  String get showcaseName => 'Toasts';

  showToast(EqToast data) {
    EqToastService.of(context).pushToast(toast: data);
  }

  @override
  List<ShowcaseWidgetData> get showcases {
    return [
      ShowcaseWidgetData(
        title: 'Toasts',
        builder: () => EqButton(
          label: Text('Show toast'),
          onTap: () => showToast(
            EqToast(
              message: 'Hi! I am a toast.',
              subtitle: 'Click me to dismiss!',
              icon: EvaIcons.star,
            ),
          ),
        ),
      ),
      ShowcaseWidgetData(
        title: 'Toast colors',
        builder: () => SeparatedColumn(
          separatorBuilder: (_, i) => SizedBox(height: 8.0),
          children: EqWidgetStatus.values
              .map((value) => SizedBox(
              width: double.infinity,
              child: EqButton(
                status: value,
                label: Text('Show ${enumToString(value)} toast'),
                onTap: () => showToast(
                  EqToast(duration: Duration(seconds: 1),
                    message: 'Hi! I am a ${enumToString(value)} toast.',
                    subtitle: 'Click me to dismiss!',
                    status: value,
                    icon: EvaIcons.star,
                  ),
                ),
              )))
              .toList(),
        ),
      ),
      ShowcaseWidgetData(
        title: 'Toast shapes',
        builder: () => SeparatedColumn(
          separatorBuilder: (_, i) => SizedBox(height: 8.0),
          children: EqWidgetShape.values
              .map((value) => SizedBox(
              width: double.infinity,
              child: EqButton(
                label: Text('Show ${enumToString(value)} toast'),
                onTap: () => showToast(
                  EqToast(
                    message: 'Hi! I am a ${enumToString(value)} toast.',
                    subtitle: 'Click me to dismiss!',
                    shape: value,
                    icon: EvaIcons.star,
                  ),
                ),
              )))
              .toList(),
        ),
      ),
    ];
  }
}

utils.dart

String enumToString(dynamic value) {
  return normalize(value.toString().split('.').last);
}

String normalize(String value) {
  String newString = "";

  for (int i = 0; i < value.length; i++) {
    var char = value[i];
    if (char.toUpperCase() == char) {
      newString += ' $char';
    } else if (i == 0) {
      newString += char.toUpperCase();
    } else {
      newString += char;
    }
  }

  return newString;
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in