vortex 0.0.4
vortex: ^0.0.4 copied to clipboard
Vortex is a first powerful Flutter framework that brings the convenience and structure of Nuxt.js to Flutter development.
Vortex #
Vortex is a powerful Flutter framework that brings the convenience and structure of Nuxt.js to Flutter development. It provides automatic routing, component management, plugin architecture, and more to streamline your Flutter development workflow.
๐ Features #
- ๐ File-based Routing: Automatically generate routes based on your file structure in the pages directory
- ๐งน Component System: Create and register reusable components with a simple API
- ๐ Plugin Architecture: Extend functionality with a flexible plugin system
- โก Reactive State Management: Built-in reactive state management solution
- ๐ Middleware Support: Add middleware to handle navigation and requests
- ๐ ๏ธ CLI Tools: Command-line tools for generating pages, components, and more
๐ Table of Contents #
- Installation
- Basic Setup
- Routing
- Components
- State Management
- Plugins
- Middleware
- CLI Commands
- Examples
- Contributing
- License
๐ Installation #
Add Vortex to your pubspec.yaml:
dependencies:
vortex: ^0.0.1
Run flutter pub get to install the package.
๐ง Basic Setup #
Initialize Vortex in your main.dart:
import 'package:flutter/material.dart';
import 'package:vortex/vortex.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Vortex.initialize();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Vortex(
child: MaterialApp(
title: 'Vortex App',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
onGenerateRoute: VortexRouter.onGenerateRoute,
initialRoute: '/',
),
);
}
}
Create a new Vortex project with the CLI:
flutter pub run vortex create --name=my_app
This will create a new Flutter project with the Vortex folder structure:
lib/
โโโ pages/ # Route pages
โโโ components/ # Reusable UI components
โโโ layouts/ # Page layouts
โโโ middleware/ # Navigation middleware
โโโ plugins/ # App plugins
โโโ store/ # State management
โโโ assets/ # Images, fonts, etc.
โโโ generated/ # Auto-generated code
๐งญ Routing #
Vortex uses a file-based routing system similar to Nuxt.js.
Basic Routes #
lib/pages/index.dart โ /
lib/pages/about.dart โ /about
lib/pages/contact.dart โ /contact
Nested Routes #
lib/pages/users/index.dart โ /users
lib/pages/users/profile.dart โ /users/profile
Dynamic Routes #
lib/pages/users/[id].dart โ /users/:id
lib/pages/blog/[...slug].dart โ /blog/* (catch-all route)
Creating a Page #
import 'package:flutter/material.dart';
import 'package:vortex/vortex.dart';
@VortexPage('/about')
class AboutPage extends StatelessWidget {
const AboutPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('About')),
body: const Center(child: Text('About Page')),
);
}
}
Generating a Page with CLI #
flutter pub run vortex page --name=contact --type=stateless
Accessing Route Parameters #
@VortexPage('/users/:id')
class UserDetailPage extends StatelessWidget {
const UserDetailPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final params = VortexRouter.of(context).params;
final userId = params['id'] ?? 'unknown';
return Scaffold(
appBar: AppBar(title: Text('User $userId')),
body: Center(child: Text('User ID: $userId')),
);
}
}
๐งน Components #
Vortex provides a component system that allows you to create reusable UI components.
Creating a Component #
// lib/components/button.dart
import 'package:flutter/material.dart';
import 'package:vortex/vortex.dart';
@Component('Button')
class Button extends StatelessWidget {
final String text;
final VoidCallback onPressed;
final Color? color;
const Button({
Key? key,
required this.text,
required this.onPressed,
this.color,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
style: color != null ? ElevatedButton.styleFrom(backgroundColor: color) : null,
child: Text(text),
);
}
}
Registering Components #
flutter pub run vortex components
Using Components #
context.component('Button')({
'text': 'Click Me',
'onPressed': () => print('Button clicked'),
'color': Colors.blue,
})
โก State Management #
Creating a Store #
import 'package:vortex/vortex.dart';
class CounterState {
final int count;
CounterState({this.count = 0});
CounterState copyWith({int? count}) {
return CounterState(count: count ?? this.count);
}
}
final counterStore = ReactiveStore<CounterState>(CounterState());
void increment() => counterStore.update((state) => state.copyWith(count: state.count + 1));
void decrement() => counterStore.update((state) => state.copyWith(count: state.count - 1));
Using the Store #
ReactiveBuilder<CounterState>(
store: counterStore,
builder: (context, state) {
return Text('Count: ${state.count}');
},
)
๐ Plugins #
Coming soon.
๐ Middleware #
Coming soon.
๐ ๏ธ CLI Commands #
vortex create- Create new Vortex projectvortex page- Generate new pagevortex component- Generate new component
๐ Examples #
Coming soon.
๐ช Contributing #
Pull requests welcome! For major changes, please open an issue first to discuss what you would like to change.
๐ License #
MIT License.
Made with โค๏ธ by the Vortex team and CodeSyncr.