CotR CLI
The cotr_cli is a simple CLI app for the code_on_the_rocks state management package.
Installationโ
dart pub global activate cotr_cli
Usageโ
cotr view -n home
The view
command will create the following contents:
- A new directory with the name of the view (ex.
home
) - A new dart file containing the
ViewModelBuilder
(ex.home_view.dart
) - A new dart file containing the
ViewModel
andViewModelBuilder
(ex.home_view_model.dart
)
Exampleโ
Input:
cotr view -n hame
Output:
home_view.dart
import 'package:code_on_the_rocks/code_on_the_rocks.dart';
import 'package:flutter/material.dart';
import 'home_view_model.dart';
class HomeView extends StatelessWidget {
const HomeView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return HomeViewModelBuilder(
builder: (context, model) {
return Scaffold(
body: Center(
child: Text('Home'),
)
);
},
);
}
}
home_view_model.dart
import 'package:code_on_the_rocks/code_on_the_rocks.dart';
import 'package:flutter/material.dart';
class HomeViewModelBuilder extends ViewModelBuilder<HomeViewModel> {
const HomeViewModelBuilder({
super.key,
required super.builder,
});
@override
State<StatefulWidget> createState() => HomeViewModel();
}
class HomeViewModel extends ViewModel<HomeViewModel> {
static HomeViewModel of_(BuildContext context) => getModel<HomeViewModel>(context);
}