Flutter:GetBuilder页面模板,可复用,视图,控制器分离
GetBuilder
页面模板,之后都会在此基础上写页面。
view
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'index.dart';
class GoodsListPage extends GetView<GoodsListController> {
const GoodsListPage({super.key});
// 主视图
Widget _buildView() {
return const Center(
child: Text("GoodsListPage"),
);
}
@override
Widget build(BuildContext context) {
return GetBuilder<GoodsListController>(
init: GoodsListController(),
id: "goods_list",
builder: (_) {
return Scaffold(
appBar: AppBar(title: const Text("goods_list")),
body: SafeArea(
child: _buildView(),
),
);
},
);
}
}
controller
import 'package:get/get.dart';
class GoodsListController extends GetxController {
GoodsListController();
_initData() {
update(["goods_list"]);
}
void onTap() {}
@override
void onInit() {
super.onInit();
}
@override
void onReady() {
super.onReady();
_initData();
}
@override
void onClose() {
super.onClose();
}
}
index 导包
library goods_list;
export './controller.dart';
export './view.dart';
路由配置
import '../pages/mall/goods_list/index.dart';
GetPage(
name: "/GoodsListPage", page: () => GoodsListPage()
),