我是新手 1-我有集团。
abstract class HomeClickEvent {}
class NewClientEvent extends HomeClickEvent{}
class NewOrderEvent extends HomeClickEvent{}
class OpenCatalogEvent extends HomeClickEvent{}
abstract class HomeClickState{}
class LoadingState extends HomeClickState{}
class NewClientState extends HomeClickState{}
class NewOrderState extends HomeClickState{}
class CatalogState extends HomeClickState{}
class HomeClickBloc extends Bloc<HomeClickEvent,HomeClickState>{
@override
HomeClickState get initialState => LoadingState();
@override
Stream<HomeClickState> mapEventToState(HomeClickEvent event) async*{
if(event is NewClientEvent){
yield NewClientState();
}else if (event is NewOrderEvent){
yield NewOrderState();
}else if(event is OpenCatalogEvent) {
yield CatalogState();
}else {
yield LoadingState();
}
}
}
2- I have main.dart
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider<HomeClickBloc>(create: (context) => HomeClickBloc(),),
],
child: MaterialApp(
title: 'Don agent',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HomePage(),
),
);
}
}
3- i have HomePage.dart with btns
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<HomeClickBloc>(context);
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text("${CONSTANTS.APP_TITLE}"),
),
body: ListView(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
InkWell(
onTap: (){
bloc.add(NewClientEvent());
},
child: buildButton("Новый клиент",Icons.add)
),
buildButton("Новый заказ",Icons.add_circle),
buildButton("Каталог товаров",Icons.scatter_plot),
],
)
],
),
);
}
Widget buildButton(String title,IconData icon){
return InkWell(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(icon,size: 50.0,),
Text("$title"),
],
),
);
}
}
现在是问题本身。 1-我正在添加一个事件以打开客户表单。以及如何打开表格?我需要创建一个单独的小部件,以便它抛出? //bloc.add(NewClientEvent());我需要使用bloc打开“客户”表单。 2-// buildButton(字符串标题,// IconData图标)。如何在此小部件中的所有按钮上使用该特定按钮。以免每次都不创建// InkWell?