Coder Social home page Coder Social logo

Comments (4)

FilledStacks avatar FilledStacks commented on August 16, 2024

Hey, it shows here how to do that.

Register your configs

void setupSnackbarUi() {
  final service = locator<SnackbarService>();

  service.registerCustomSnackbarConfig(
    variant: SnackbarType.blueAndYellow,
    config: SnackbarConfig(
      backgroundColor: Colors.blueAccent,
      textColor: Colors.yellow,
      borderRadius: 1,
      dismissDirection: SnackDismissDirection.HORIZONTAL,
    ),
  );

  service.registerCustomSnackbarConfig(
    variant: SnackbarType.greenAndRed,
    config: SnackbarConfig(
      backgroundColor: Colors.white,
      titleColor: Colors.green,
      messageColor: Colors.red,
      borderRadius: 1,
    ),
  );
}

Show the config

_snackbarService.showCustomSnackBar(
  variant: SnackbarType.blueAndYellow,
  message: 'Blue and yellow',
  title: 'The message is the message',
  duration: Duration(seconds: 2),
  onTap: (_) {
    print('snackbar tapped');
  },
  mainButtonTitle: 'Undo',
  onMainButtonTapped: () => print('Undo the action!'),
);

from flutter-tutorials.

evicoach avatar evicoach commented on August 16, 2024

There are two other optional arguments, named titleText and messageText that are TextWidget, but I can't supply their values when calling
_snackbarService.showCustomSnackBar(
duration: Duration(seconds: 2),
title: exception.toString(),
variant: SnackbarType.success,
message: '',
// message: exception.toString(),
);
I need those two arguments to be able to center align the title and the message. currently they are left aligned and there is no way to center them

from flutter-tutorials.

FilledStacks avatar FilledStacks commented on August 16, 2024

@evicoach you won't be able to pass a widget directly into it. I don't mix UI code and business logic. I've added titleTextAlign and messageTextAlign to the snackbarConfig model. Let me know if it works. v 0.6.6

from flutter-tutorials.

evicoach avatar evicoach commented on August 16, 2024

It's working fine now. Thank you very much

from flutter-tutorials.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.