Skip to content

Commit

Permalink
Add PageView solution
Browse files Browse the repository at this point in the history
  • Loading branch information
xdd666t committed Sep 2, 2021
1 parent 75bc4b8 commit 05a1919
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 30 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ group 'com.tao.getx'
// the corresponding settings in Plugin.xml will be invalid
// The two settings below are updated frequently, so put them here
// The version number is modified here
version '3.0.7'
version '3.0.8'
// must!!!
sourceCompatibility = 1.8

Expand Down Expand Up @@ -53,6 +53,7 @@ patchPluginXml {
<li>add some snippets code</li>
<li>view and logic separate</li>
<li>GetBuilder adds automatic dispose Wrap Widget</li>
<li>Add PageView solution</li>
</ul>
<h1>2.1.x</h1>
Expand Down
19 changes: 14 additions & 5 deletions src/main/kotlin/NewGetX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class NewGetX : AnAction() {
}
data.useFolder = view.folderBox.isSelected
data.usePrefix = view.prefixBox.isSelected
data.isPageView = view.pageViewBox.isSelected
data.autoDispose = view.disposeBox.isSelected
data.addLifecycle = view.lifecycleBox.isSelected
data.addBinding = view.bindingBox.isSelected
Expand Down Expand Up @@ -145,15 +146,23 @@ class NewGetX : AnAction() {

//content need deal
private fun dealContent(name: String, inputFileName: String, outFileName: String): String {
//deal auto dispose
var defaultFolder = "/templates/"
if (data.autoDispose && inputFileName.contains("view.dart")) {
defaultFolder += "auto/"
//deal auto dispose or pageView
var defaultFolder = "/templates/normal/"

// view.dart
if (inputFileName.contains("view.dart")) {
if (data.autoDispose) {
defaultFolder = "/templates/auto/"
}

if (data.isPageView) {
defaultFolder = "/templates/pageView/"
}
}

//add lifecycle
if (data.addLifecycle && inputFileName.contains("logic.dart")) {
defaultFolder += "lifecycle/"
defaultFolder = "/templates/lifecycle/"
}

//read file
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/helper/DataService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class DataService : PersistentStateComponent<DataService> {
@JvmField
var usePrefix = GetXConfig.usePrefix

//default false
@JvmField
var isPageView = GetXConfig.isPageView

//auto dispose GetXController
@JvmField
var autoDispose = GetXConfig.autoDispose
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/helper/GetXConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ object GetXConfig {
//default false
const val usePrefix = false

//pageView
const val isPageView = false

//auto dispose GetXController
const val autoDispose = false

Expand Down
33 changes: 26 additions & 7 deletions src/main/kotlin/view/GetXTemplateView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class GetXTemplateView(private val getXListener: GetXListener) {
*/
lateinit var folderBox: JCheckBox
lateinit var prefixBox: JCheckBox
lateinit var pageViewBox: JCheckBox
lateinit var disposeBox: JCheckBox
lateinit var lifecycleBox: JCheckBox
lateinit var bindingBox: JCheckBox
Expand All @@ -42,8 +43,8 @@ class GetXTemplateView(private val getXListener: GetXListener) {
override fun keyReleased(e: KeyEvent) {}
}

private val actionListener = ActionListener { e ->
if (e.actionCommand == "Cancel") {
private val actionListener = ActionListener {
if (it.actionCommand == "Cancel") {
dispose()
} else {
confirm()
Expand Down Expand Up @@ -118,6 +119,16 @@ class GetXTemplateView(private val getXListener: GetXListener) {
setMargin(prefixBox)
function.add(prefixBox)

//pageView
pageViewBox = JCheckBox("isPageView", data.isPageView)
setMargin(pageViewBox)
function.add(pageViewBox)

//add binding
bindingBox = JCheckBox("addBinding", data.addBinding)
setMargin(bindingBox)
function.add(bindingBox)

//auto dispose
disposeBox = JCheckBox("autoDispose", data.autoDispose)
setMargin(disposeBox)
Expand All @@ -128,13 +139,21 @@ class GetXTemplateView(private val getXListener: GetXListener) {
setMargin(lifecycleBox)
function.add(lifecycleBox)

//add binding
bindingBox = JCheckBox("addBinding", data.addBinding)
setMargin(bindingBox)
function.add(bindingBox)

container.add(function)
setSpacing(container)


/// deal listener
pageViewBox.addActionListener {
if (disposeBox.isSelected && pageViewBox.isSelected) {
disposeBox.isSelected = false
}
}
disposeBox.addActionListener {
if (disposeBox.isSelected && pageViewBox.isSelected) {
pageViewBox.isSelected = false
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<li>使用:<a href="https://juejin.cn/post/6924104248275763208"> Flutter GetX使用---简洁的魅力!</a></li>
<li>原理:<a href="https://juejin.cn/post/6984593635681517582"> Flutter GetX深度剖析 | 我们终将走出自己的路</a></li>
<h3>Statement</h3>
<li>Some fast code snippet prompt come from <a href="/cjamcu/getx-snippets-intelliJ/blob/master/src/main/resources/liveTemplates/getx.xml"> getx-snippets-intelliJ</a></li>
<li>Part of fast code snippet prompt come from <a href="/cjamcu/getx-snippets-intelliJ/blob/master/src/main/resources/liveTemplates/getx.xml"> getx-snippets-intelliJ</a></li>
</ul>
]]></description>

Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/templates/auto/easy/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class @namePage extends StatefulWidget {
}

class _@namePageState extends State<@namePage> {
final @nameLogic logic = Get.put(@nameLogic());
final logic = Get.put(@nameLogic());

@override
Widget build(BuildContext context) {
return Container();
}
Widget build(BuildContext context) {
return Container();
}

@override
void dispose() {
Expand Down
11 changes: 5 additions & 6 deletions src/main/resources/templates/auto/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';
import 'state.dart';

class @namePage extends StatefulWidget {
@override
_@namePageState createState() => _@namePageState();
}

class _@namePageState extends State<@namePage> {
final @nameLogic logic = Get.put(@nameLogic());
final @nameState state = Get.find<@nameLogic>().state;
final logic = Get.put(@nameLogic());
final state = Get.find<@nameLogic>().state;

@override
Widget build(BuildContext context) {
return Container();
}
Widget build(BuildContext context) {
return Container();
}

@override
void dispose() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/lifecycle/logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:get/get.dart';
import 'state.dart';

class @nameLogic extends GetxController {
final state = @nameState();
final @nameState state = @nameState();

@override
void onReady() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:get/get.dart';
import 'logic.dart';

class @namePage extends StatelessWidget {
final @nameLogic logic = Get.put(@nameLogic());
final logic = Get.put(@nameLogic());

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import 'package:get/get.dart';
import 'state.dart';

class @nameLogic extends GetxController {
final state = @nameState();
final @nameState state = @nameState();
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';
import 'state.dart';

class @namePage extends StatelessWidget {
final @nameLogic logic = Get.put(@nameLogic());
final @nameState state = Get.find<@nameLogic>().state;
final logic = Get.put(@nameLogic());
final state = Get.find<@nameLogic>().state;

@override
Widget build(BuildContext context) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/templates/pageView/easy/view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class @namePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final logic = Get.put(@nameLogic());

return Container();
}
}
14 changes: 14 additions & 0 deletions src/main/resources/templates/pageView/view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class @namePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final logic = Get.put(@nameLogic());
final state = Get.find<@nameLogic>().state;

return Container();
}
}

0 comments on commit 05a1919

Please sign in to comment.