GetBuilder
页面模板,之后都会在此基础上写页面。
view
js
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
js
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 导包
js
library goods_list;
export './controller.dart';
export './view.dart';
路由配置
js
import '../pages/mall/goods_list/index.dart';
GetPage(
name: "/GoodsListPage", page: () => GoodsListPage()
),