Styledwidget - Simplifying widget style in Flutter.

Overview


Simplifying your widget tree structure by defining widgets using methods.

   Buy Me A Coffee


Thanks to the introduction of extension methods in Dart 2.7.0, styled_widget makes it possible to build widget tree`s more readable and efficient.

styled_widget is build as a tool to enhance your Flutter development experience and to seamlessly integrate with your codebase.

Showcase

Design, Code Design, Code Design, Code

Basic example

styled_widget has a bottom up approach to building widget`s. This means you start with the inner most element and layer widget`s on top. The following example is structured as follows: Icon -> blue circle -> light blue circle -> card -> background

Icon(OMIcons.home, color: Colors.white)
  .padding(all: 10)
  .decorated(color: Color(0xff7AC1E7), shape: BoxShape.circle)
  .padding(all: 15)
  .decorated(color: Color(0xffE8F2F7), shape: BoxShape.circle)
  .padding(all: 20)
  .card(
    elevation: 10,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(20),
    ),
  )
  .alignment(Alignment.center)
  .backgroundColor(Color(0xffEBECF1));
Raw Flutter (click to show)
  
DecoratedBox(
  decoration: BoxDecoration(
    color: Color(0xffEBECF1),
  ),
  child: Align(
    alignment: Alignment.center,
    child: Card(
      elevation: 10,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(20),
      ),
      child: Padding(
        padding: EdgeInsets.all(20),
        child: DecoratedBox(
          decoration: BoxDecoration(
            color: Color(0xffE8F2F7),
            shape: BoxShape.circle,
          ),
          child: Padding(
            padding: EdgeInsets.all(15),
            child: DecoratedBox(
              decoration: BoxDecoration(
                color: Color(0xff7AC1E7),
                shape: BoxShape.circle,
              ),
              child: Padding(
                padding: EdgeInsets.all(10),
                child: Icon(
                  OMIcons.home,
                  color: Colors.white,
                ),
              ),
            ),
          ),
        ),
      ),
    ),
  ),
);

Docs

See the documentation at styled_widget/wiki for more information about using styled_widget!

Quicklinks

Comments
  • Support for directional widgets (padding, positioned, borderRadius)

    Support for directional widgets (padding, positioned, borderRadius)

    This PR should solve this issue #59. I could make them in one single method with all the method args for each, instead of having two methods:

    • padding, paddingDirectional
    • positioned, positionedDirectional
    • borderRadius, borderRadiusDirectional

    But this would confuse the developer which arg to use if we made a method that takes all these args:

    • start
    • end
    • top
    • bottom
    • left
    • right
    • horizontal
    • vertical
    • all

    I think what I did is much more convenient to have those methods separated, like Flutter does:

    • EdgeInsets, EdgeInsetsDirectional
    • Positioned, PositionedDirectional
    • BorderRadius, BorderRadiusDirectional
    opened by devmuaz 9
  • Decoupling facilities

    Decoupling facilities

    These facilities help with decoupling styles while retaining the hot reload functionality.

    class Styles {
      static TextWrapper get myBeautifulLabel =>
          (Text text) => text.fontSize(14).textColor(Colors.lightBlue);
    }
    ...
    Text('Lorem Ipsum').wrap(Styles.myBeautifulLabel)
    ...
    

    Also, the context can also be provided with wrapWithContext for media queries amongst other things.

    opened by moraispgsi 9
  • TextTheme support

    TextTheme support

    It would be nice to have an API where you could apply styles directly from the theme.

    Example:

    Text("Some text").body1()
    Text("Some text").caption()
    

    I achieve this in my own app by creating a StyledTheme widget with a static global key that wraps theme. Then wrap the application in StyledTheme as the child of MaterialApp.

    class StyledTheme extends StatefulWidget {
      final Widget child;
    
      StyledTheme({Key key, this.child}) : super(key: key);
    
      @override
      _StyledThemeState createState() => _StyledThemeState();
    
      static ThemeData get theme {
        return Theme.of(_StyledThemeState.styledThemeKey.currentContext);
      }
    }
    
    class _StyledThemeState extends State<StyledTheme> {
      static GlobalKey<_StyledThemeState> styledThemeKey = GlobalKey<_StyledThemeState>();
    
      @override
      Widget build(BuildContext context) {
        return Theme(
          key: styledThemeKey,
          data: theme,
          child: widget.child,
        );
      }
    }
    

    I have not been able to find a better way to acheive this.

    opened by ryan-sf 8
  • Null-safety issue with animated translate

    Null-safety issue with animated translate

    In 0.3.1 code like: SomeWidget(...).translate(offset: ..., animate: true) throws:

    ======== Exception caught by widgets library =======================================================
    The following _CastError was thrown building _StyledAnimatedBuilder(dependencies: [_StyledInheritedAnimation]):
    type 'Null' is not a subtype of type 'AlignmentGeometryTween' in type cast
    
    The relevant error-causing widget was: 
      _StyledAnimatedBuilder file:///Users/ds/.pub-cache/hosted/pub.dartlang.org/styled_widget-0.3.1/lib/src/extensions/widget_extension.dart:861:13
    When the exception was thrown, this was the stack: 
    #0      _AnimatedTransformState.forEachTween (package:styled_widget/src/animated_widget.dart:263:9)
    #1      ImplicitlyAnimatedWidgetState._constructTweens (package:flutter/src/widgets/implicit_animations.dart:427:5)
    #2      ImplicitlyAnimatedWidgetState.initState (package:flutter/src/widgets/implicit_animations.dart:381:5)
    #3      AnimatedWidgetBaseState.initState (package:flutter/src/widgets/implicit_animations.dart:553:11)
    #4      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4632:57)
    ...
    

    I think you should change as AlignmentGeometryTween; to as AlignmentGeometryTween?; at mentioned in stack trace line 263

    bug 
    opened by f69 7
  • Decoupling styles

    Decoupling styles

    Hi, One issue that seems to be present when we decouple the styles is that the hot reload no longer works when the styles are changed (at least it is my experience with division), is there anything that can be done about this?

    opened by moraispgsi 7
  • Is there any widget like Parent() on division

    Is there any widget like Parent() on division

    Hi, first of all I really love your division library. I used Parent() a lot to create "wrap_content" layout on flutter. How can I build widget like Parent() using styled_widget? Thanks.

    opened by RakaAlrian 6
  • Add support for (toColumn/toRow).separator

    Add support for (toColumn/toRow).separator

    Would it be possible to add a separator builder, so we can do something like:

    [
       Text(),
       Text(),
    ].toColumn(separator: ()=>SizedBox(height: 8))
    
    enhancement 
    opened by esDotDev 6
  • Add size(w,h) + 9 alignment options: center(), centerLeft() etc

    Add size(w,h) + 9 alignment options: center(), centerLeft() etc

    I often find myself having to chain both width and height, width(50).height(50) would read better as size(50,50)

    Additionally, when alignment things, it can be overly verbose: .alignment(Alignment.center) could just be center()

    opened by esDotDev 6
  • Support for TextSpans

    Support for TextSpans

    First of all: I was already using your division-library and now I'm using this. I like both very much! 👌

    I was searching to achieve something like this:

    Text.rich(
      TextSpan(
        children: <InlineSpan>[
          TextSpan(text: 'All data will be deleted and '),
          TextSpan(
            text: 'this cannot be undone!',
            style: TextStyle(
              color: Colors.red,
              fontWeight: FontWeight.bold,
            ),
          ),
        ],
      ),
    ),
    

    but couldn't find anything similar in division or styled_widgets (I was looking for either Txt.rich or just Txt(children:..), for styled_widgets Text(..).rich/children(..)).

    Am I missing something or is this a possible future feature? If so, do you already have some ideas about this or do you need some inspiration? :)

    enhancement 
    opened by fibbers 5
  • Stacks support

    Stacks support

    Is it possible to create Stacks and position them to a specific percentage of their parent width,heigh?

    Thanks for your work with styled_widget, it is fantastic!

    enhancement 
    opened by gloomie 4
  • Possibility to create a base style as to not repeat

    Possibility to create a base style as to not repeat

    I saw its possible to use the Styled.widget(child) in the example, but this does not seem have the methods that are available for Text e.g. textColor().

                Text('NAME')
                    .fontSize(16)
                    .fontWeight(FontWeight.w600)
                    .textColor(Colors.black),
    
                Text('AGE')
                    .fontSize(16)
                    .fontWeight(FontWeight.w600)
                    .textColor(Colors.black),
    

    Imagine we had something like above, it seems redundant to repeat ourselves. Is there a possibility to create a base style that can be applied to all Text widgets

    e.g.

         final styledText= (Widget child) => StyledText.widget(child)
            .textColor(Colors.black)
            .fontSize(16)
    
         styledText(Text('NAME')),
         styledText(Text('AGE')),
    

    or

    Text('NAME')
      .applyStyles(?)
    
    Text('AGE')
      .applyStyles(?)
    
    opened by linxydmhg 4
  • Add Material & MouseRegion extention

    Add Material & MouseRegion extention

    The use case for .material is mostly when you just want to wrap something in Material so that widgets that require material parents work correctly. I kinda understand that maybe this use case doesn't warrant adding it to this repository so I can revert it if you want :).

    opened by chomosuke 0
  • name conflicts with the origin properties

    name conflicts with the origin properties

    .textWidthBasic() .textDirection() conflict with the origin same name properties

    Screen Shot 2022-04-24 at 13 07 52

    Flutter 2.13.0-0.2.pre • channel beta • https://github.com/flutter/flutter.git Framework • revision 8662e22bac (4 days ago) • 2022-04-20 08:21:52 -0700 Engine • revision 24a02fa5ee Tools • Dart 2.17.0 (build 2.17.0-266.5.beta) • DevTools 2.12.2

    opened by ash0080 6
  • Effect on Performance

    Effect on Performance

    Hey guys! I just discovered Styled_Widgets and I'd like to say Kudos! for building such a wonderful library.

    I have 2, rather simple questions.

    1. Would using this package have any effect on the performance of the app, assuming that it is a graphically intensive application?
    2. Can I use this to build a desktop app? (I am assuming that I can because of how flutter compiles Dart code to desktop bundles)

    Thanks!

    opened by gfyre 4
  • Wiki Demo App Missing Argument

    Wiki Demo App Missing Argument

    Scale method has named parameter and hasn't declared on what type of argument does pressed ? 0.95 : 1.0 would be.

    Line 231 .scale(pressed ? 0.95 : 1.0, animate: true)

    documentation help wanted 
    opened by ronealdenila 2
Owner
Rein Gundersen Bentdal
Student at NTNU and co-founder of Hybelkaninene ANS
Rein Gundersen Bentdal
Neumorphic style - Example app with Flutter that displays a neumorphic style container

Flutter Neumorphic Style Example App Example app with Flutter that displays a ne

Piyush Nagpal 2 Mar 24, 2022
Flutter page widget that is dismissed by swipe gestures, with Hero style animations, Inspired by Facebook and Instagram stories.

dismissible_page ?? ?? Creates page that is dismissed by swipe gestures, with Hero style animations, Inspired by FB, IG stories. Live Demo Contents Su

Tornike 76 Dec 22, 2022
An Instagram like text editor Flutter widget that helps you to change your text style.

TextEditor An instagram like text editor widget for flutter Show some ❤️ and star the repo to support the project Features Edit TextStyle object font

Mehdi Zarepour 68 Dec 16, 2022
A very easy-to-use navigation tool/widget for having iOS 13 style stacks.

cupertino_stackview A very easy-to-use navigation tool/widget for having iOS 13 style stacks. It is highly recommended to read the documentation and r

AliYigitBireroglu 49 Nov 18, 2022
A highly customisable and simple widget for having iOS 13 style tab bars.

cupertino_tabbar A highly customisable and simple widget for having iOS 13 style tab bars. It is highly recommended to read the documentation and run

AliYigitBireroglu 98 Oct 31, 2022
Widget to count the amount of nested widget tree, useful in the dynamic construction of the interface when it is important to know the depth of widget.

widget_tree_depth_counter Widget Tree Depth Counter WidgetTreeDepthCounter is a simple widget to count the amount of nested widget tree, useful in the

Riccardo Cucia 4 Aug 1, 2022
MindInventory 15 Sep 5, 2022
Flutter cupertino style date picker.

Flutter Cupertino Date Picker [pub packages] | 中文说明 Flutter cupertino date picker. Usage 1. Depend Add this to you package's pubspec.yaml file: depend

Dylan Wu 333 Dec 26, 2022
Flutter cupertino style date picker.

Flutter Cupertino Date Picker [pub packages] | 中文说明 Flutter cupertino date picker. Usage 1. Depend Add this to you package's pubspec.yaml file: depend

Dylan Wu 333 Dec 26, 2022
🎮 Style your flutter game with a beautiful splash screen.

Flame Splash Screen Style your flame game with a beautiful splash screen. This package includes a FlameSplashScreen widget. Install Add flame_splash_s

Flame Engine 38 Sep 13, 2022
The easiest way to style custom text snippets in flutter

Super Rich Text Check it out at Pub.Dev The easiest way to style custom text snippets Help Maintenance I've been maintaining quite many repos these da

Woton Sampaio 14 Nov 4, 2022
Iosish indicator - 🍎 Create awesome and simple iOS style floating indicator which can be found when silent/sleep mode switched on Flutter.

Iosish indicator - ?? Create awesome and simple iOS style floating indicator which can be found when silent/sleep mode switched on Flutter.

Kim Seung Hwan 2 Apr 1, 2022
A simple "Hello, World" style Flutter app.

Flutter Sample App - Hello World This is a simple Flutter (Dart) app with a single view. The intention of this application is to demonstrate the usage

Bitrise Examples 1 May 9, 2022
A mobile banking ui design app in a neomorphism style built using flutter.

Mobile Banking App UI A mobile banking app ui design in a neomorphism style built using Flutter. Show some ❤️ and star ⭐ the repo, it makes me to shar

Vinoth Vino 66 Oct 11, 2022
Custom style-dictionary transforms and formats to generate Flutter resources from a Figma Design Token plugin export..

style-dictionary-figma-flutter An extension to style-dictionary to support more custom types with Flutter as target platform. It supports the custom t

Aloïs Deniel 24 Dec 30, 2022
C2F can convert css style to Flutter code online.

C2F is an interesting little project. I hope to find a way to convert css styles to flutter styles. I believe many web developers will like it. https:

Anonymous Namespace 232 Dec 29, 2022
Create bulk instagram quotes posts with custom background, style, font, size. built using flutter

Mini Canva minicanva.com Bulk Image Generator from given list of quotes, lines ?? Purpose Etsy is an E-commerce platform where we can sell digital goo

Ashish Pipaliya 7 Oct 29, 2022
Flutter themes consistent with GitHub's Primer style guidelines

primer_flutter Flutter themes consistent with Primer style guidelines DISCLAIMER: This project is not affiliated with the Primer or GitHub organizatio

Reuben Turner 6 Aug 24, 2022
Xtyle means "Multilingual-style" - Flutter Package

Xtyle Xtyle means "Multilingual-style". As a design requirement, there are many requests for different fonts in English and native language. This pack

Theo / Taeyoon Kang 2 Sep 13, 2022