css 1.0.5

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

A CSS library for Flutter that facilitates minimal code styling of widgets, simplifying the development of consistent and elegant UI.

CSS

This extension provides a convenient way to style Flutter widgets using CSS-like properties. It offers options for setting padding, margin, colors, fonts, events, icons, borders, and more.

Usage

To use this extension, simply import it and apply it to your widget using the css method. Here's an example:

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

void main() {
  runApp(MaterialApp(home: Main(), debugShowCheckedModeBanner: false));
}

class Main extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('css Demo'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Center(),
          Text("text").css(
            w: double.infinity,
            p: 0,
            my: 10,
            r: 0,
            borderColor: Colors.teal,
            borderWidth: 1,
            fontSize: 20,
            fontWeight: FontWeight.bold,
            icon: Icon(Icons.dashboard_rounded),
            onPressed: () => print("onPressed"),
            onLongPress: () => print("onLongPress"),
            onHover: (bool) {
              if (bool) print("onHover $bool");
              if (!bool) print("onHover $bool");
            },
          )
        ],
      ),
    );
  }
}

Supported Properties

Width and Height

PropertyTypeDescriptionExample
wdoubleWidthw: double.infinity
hdoubleHeighth: 100

Padding and Margin

PropertyTypeDescriptionExample
pdoublePadding (all sides)p: 16
pxdoubleHorizontal paddingpx: 10
pydoubleVertical paddingpy: 20
ptdoubleTop paddingpt: 8
prdoubleRight paddingpr: 12
pbdoubleBottom paddingpb: 8
pldoubleLeft paddingpl: 12
mdoubleMargin (all sides)m: 16
mxdoubleHorizontal marginmx: 10
mydoubleVertical marginmy: 20
mtdoubleTop marginmt: 8
mrdoubleRight marginmr: 12
mbdoubleBottom marginmb: 8
mldoubleLeft marginml: 12

Colors

PropertyTypeDescriptionExample
cbdynamicBackground colorcb: Colors.yellow
ctdynamicText colorct: Colors.blue

Fonts

PropertyTypeDescriptionExample
fontSizedoubleFont sizefontSize: 16
fontFamilystringFont familyfontFamily: "Poppins"
fontWeightdynamicFont weightfontWeight: FontWeight.bold

Events

PropertyTypeDescriptionExample
onPressedfunctionOn press eventonPressed: ()=>print("onPressed")
onLongPressfunctionOn long press eventonLongPress: ()=>print("onLongPress")
onHoverfunctionOn hover eventonHover: (bool)=>bool? print("onHover $bool"):print("onHover $bool")

Icon

PropertyTypeDescriptionExample
iconwidgetIcon widgeticon: Icon(Icons.add)

Borders

PropertyTypeDescriptionExample
borderColordynamicBorder colorborderColor: Colors.teal
borderWidthdoubleBorder widthborderWidth: 2
rdoubleBorder radiusr: 8

Notes

Don't forget to like this 👍at https://pub.dev/packages/css