rad 0.6.2 rad: ^0.6.2 copied to clipboard
A zero-dependency frontend framework for writing web apps in plain Dart. Inspired from Flutter.
Rad #
Rad is a frontend framework for creating fast and interactive websites using Dart. It's inspired from Flutter and shares same programming paradigm. It has all the best bits of Flutter(StatefulWidgets, Builders) and allows you to use web technologies(HTML and CSS) in your app.
Quick links #
Example #
Let's take a look at an example written using Rad:
class HomePage extends StatelessWidget
{
@override
build(context) {
return Text("hello world");
}
}
How about that? if you're familiar with Flutter it don't even need an explanation. But there are some differences that should be discussed before you begin using Rad,
Differences #
-
First off, we don't use a rendering engine to render a widget or anything like that. Widgets are mapped to HTML tags and composed together they way you describe them. This means every widget has a corresponding HTML tag in DOM, and your application has complete access to document(DOM).
-
For designing a interface, you've to use HTML. And guess what? there are widgets for that.
Let's take this HTML snippet:
<span class="heading big"> <strong> hellow </strong> </span>
Here's how its equivalent will be written using widgets:
Span( classAttribute: "heading big", children: [ Strong(innerText: "hellow"), ], );
Talking more about UI, there are no layout/style specific widgets like you've Container and Stack widgets in Flutter. Just think about it for a sec? we don't really need them as most of things can be done using HTML tags and CSS.
Just for sake of example, let's say you want a Stack widget,
- Create a Stack entry:
Widget StackEntry(Widget widget) { return Division( style: "position:absolute;top:0;left:0;", children: [widget], ); // Division = HTML's div }
- Create a Stack container
Widget Stack({required List<Widget> children}) { return Division( style: "position:relative;", children: entries, ); }
- Well done! Here's our newly created Stack widget
This was just an example, you don't really need these type of widgets when you can use a CSS framework of your choice.Stack( children: [ StackEntry(Text("hellow 1")), StackEntry(Text("hellow 2")), ] )
- Create a Stack entry:
-
Rad's doesn't rebuild widgets multiple times a second, which means for animations you've to turn to CSS.
-
Lastly, Rad is fast, thanks to its tiny core and number of optimizations on top of that.
Widgets Index #
Below is the list of available widgets in this framework.
Some widgets are named after Flutter widgets because they either works exactly same or can be used to acheive same things but in a differnet way(more or less). All those widgets are marked according to their similarity level.
Markings:
- exact: Works exactly same.
- same: Works nearly the same way.
- different: Works different.
Please note that these markings are based on my understanding of Flutter widgets/src. If you happen to find any big differences, do let me know.
Main #
Navigator/Routing #
Abstract #
- InheritedWidget [exact]
- StatelessWidget [exact]
- StatefulWidget [same]
Builders #
- FutureBuilder [exact]
- StreamBuilder [exact]
- ValueListenableBuilder [exact]
Elements #
- Text [different]
- RawMarkUp
- GestureDetector
HTML #
Why Dart? #
I actually tried writing this in TypeScript before. While we can do awesome things with types in TS, it also inherits craziness from JS (has to bind 'this', use arrow fun, and more things like that). Later I decided to give Dart a try and I quickly realized that Dart is a very underrated language. You don't have to trust me on that. I had wrote a lot of Dart code with Flutter, but the fact that I choosed TS at first place really shows how underrated Dart actually is. I am thankful to all the people who helped create Dart and/or contributing to it, one way or the other.