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"),);}@overrideWidget 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() {}@overridevoid onInit() {super.onInit();}@overridevoid onReady() {super.onReady();_initData();}@overridevoid 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()
),