Skip to content

Commit

Permalink
666
Browse files Browse the repository at this point in the history
  • Loading branch information
顾飞 committed Jan 22, 2023
1 parent 283a9c0 commit cd9087a
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 52 deletions.
3 changes: 2 additions & 1 deletion lib/modules/flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Flutter {
}

static Future<void> create(
String flutterPath,
String path,
String name,
String? org,
Expand All @@ -79,7 +80,7 @@ class Flutter {
await Directory(path).create(recursive: true);

await Process.run(
'flutter',
flutterPath,
[
'create',
'--no-pub',
Expand Down
16 changes: 8 additions & 8 deletions lib/modules/structure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import 'package:path/path.dart' as p;

class Structure {
static final _paths = [
p.join(Directory.current.path, '/lib/modules'),
p.join(Directory.current.path, '/lib/assets/fonts'),
p.join(Directory.current.path, '/lib/assets/images'),
p.join(Directory.current.path, '/lib/widgets'),
p.join(Directory.current.path, '/lib/pages'),
p.join(Directory.current.path, '/lib/routes'),
p.join(Directory.current.path, '/lib/data'),
p.join(Directory.current.path, '/lib/models'),
p.join(Directory.current.path, 'lib/modules'),
p.join(Directory.current.path, 'lib/assets/fonts'),
p.join(Directory.current.path, 'lib/assets/images'),
p.join(Directory.current.path, 'lib/widgets'),
p.join(Directory.current.path, 'lib/pages'),
p.join(Directory.current.path, 'lib/routes'),
p.join(Directory.current.path, 'lib/data'),
p.join(Directory.current.path, 'lib/models'),
];
static Future<void> create() async {
await Directory(p.join(Directory.current.path, 'lib')).delete(recursive: true);
Expand Down
13 changes: 7 additions & 6 deletions lib/pages/home/components/picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import 'package:flutter_desktop_cli/widgets/click.dart';
class Picker extends StatefulWidget {
final String title;
final PickerType type;
String path;
List<String>? allowedExtensions;
final Function(String path) onFinished;
Picker({
super.key,
required this.title,
required this.onFinished,
required this.type,
this.path = '',
this.allowedExtensions,
});

Expand All @@ -22,7 +24,6 @@ class Picker extends StatefulWidget {
enum PickerType { file, folder }

class _PickerState extends State<Picker> {
var path = '';
@override
Widget build(BuildContext context) {
Color color = Colors.black45;
Expand All @@ -45,7 +46,7 @@ class _PickerState extends State<Picker> {
),
child: Text(
locale: const Locale('zh', 'CN'),
path,
widget.path,
maxLines: 1,
overflow: TextOverflow.visible,
),
Expand All @@ -58,16 +59,16 @@ class _PickerState extends State<Picker> {
if (widget.type == PickerType.folder) {
var dirPath = await getDirectoryPath();
setState(() {
path = dirPath ?? '';
widget.path = dirPath ?? '';
});
widget.onFinished(path);
widget.onFinished(widget.path);
} else if (widget.type == PickerType.file) {
var file = await openFile(
acceptedTypeGroups: [XTypeGroup(label: '文件', extensions: widget.allowedExtensions)]);
setState(() {
path = file?.path ?? '';
widget.path = file?.path ?? '';
});
widget.onFinished(path);
widget.onFinished(widget.path);
}
},
child: Container(
Expand Down
53 changes: 49 additions & 4 deletions lib/pages/home/home_controller.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
// ignore_for_file: use_build_context_synchronously

import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_desktop_cli/pages/home/components/picker.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:getwidget/getwidget.dart';
import 'package:process_run/shell.dart';

import '../../modules/flutter.dart';
import '../../modules/structure.dart';
import '../../widgets/desktop_route.dart';

class HomeController extends GetxController {
RouteController rc = RouteController();
TextEditingController projectNameC = TextEditingController(text: 'test');
TextEditingController companyNameC = TextEditingController(text: 'com.igf');
TextEditingController projectNameC = TextEditingController(text: '');
TextEditingController companyNameC = TextEditingController(text: 'com.example');
var projectPath = '';
var projectIconPath = '';
var log = ''.obs;
var isTask = false;
String? flutterPath;
final box = GetStorage();
void generateDesktopProject(BuildContext context) async {
var path = await which('flutter');
if (path != null) {
flutterPath = path;
}
if (flutterPath == null) {
setFlutterPath(context);
return;
}
if (isTask) {
GFToast.showToast(
'项目正在构建中,请稍后尝试。',
Expand Down Expand Up @@ -68,7 +83,8 @@ class HomeController extends GetxController {
var time = Stopwatch();
time.start();
printLog('开始构建项目...');
await Flutter.create(projectPath, projectNameC.text.trim(), companyNameC.text.trim(), 'swift', 'java');
await Flutter.create(
flutterPath!, projectPath, projectNameC.text.trim(), companyNameC.text.trim(), 'swift', 'java');
printLog('开始生成项目结构...');
await Structure.create();
printLog('开始添加依赖插件...');
Expand All @@ -84,7 +100,36 @@ class HomeController extends GetxController {
print(time.elapsed.inMicroseconds);
}

@override
void onInit() {
flutterPath = box.read('flutter_path') ?? '';
super.onInit();
}

void printLog(String text) {
log.value += '$text\n';
}

void setFlutterPath(BuildContext context) {
showDialog(
context: context,
builder: (context) {
return Dialog(
child: Container(
width: 400,
height: 100,
padding: const EdgeInsets.all(20),
child: Picker(
title: '选择flutter的执行路径',
path: flutterPath ?? '',
onFinished: (path) {
flutterPath = path;
box.write('flutter_path', flutterPath);
},
type: PickerType.file),
),
);
},
);
}
}
68 changes: 41 additions & 27 deletions lib/pages/home/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_desktop_cli/pages/home/components/input.dart';
import 'package:flutter_desktop_cli/pages/home/components/picker.dart';
import 'package:flutter_desktop_cli/widgets/click.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

Expand All @@ -15,36 +16,49 @@ class HomePage extends GetView<HomeController> {
Widget build(BuildContext context) {
return DesktopPage(
title: '主界面',
body: ListView(
padding: const EdgeInsets.only(top: 50, left: 200, right: 200),
body: Stack(
children: [
Input(title: '项目名称', hintText: '项目名称只能使用字母、数字、下划线组成', controller: controller.projectNameC),
Input(title: '公司组织', hintText: 'com.example', controller: controller.companyNameC),
/* Picker(
title: '软件图标',
onFinished: (path) {
controller.projectIconPath = path;
},
type: PickerType.file,
allowedExtensions: const ['ico'],
), */
Picker(
title: '项目路径',
type: PickerType.folder,
onFinished: (path) {
controller.projectPath = path;
},
ListView(
padding: const EdgeInsets.only(top: 50, left: 200, right: 200),
children: [
Input(title: '项目名称', hintText: '项目名称只能使用字母、数字、下划线组成', controller: controller.projectNameC),
Input(title: '公司组织', hintText: 'com.example', controller: controller.companyNameC),
/* Picker(
title: '软件图标',
onFinished: (path) {
controller.projectIconPath = path;
},
type: PickerType.file,
allowedExtensions: const ['ico'],
), */
Picker(
title: '项目路径',
type: PickerType.folder,
onFinished: (path) {
controller.projectPath = path;
},
),
GFButton(
onPressed: () {
controller.generateDesktopProject(context);
},
text: '创建项目',
size: 30,
shape: GFButtonShape.square,
fullWidthButton: true,
),
Obx(() => Text(controller.log.value))
],
),
GFButton(
onPressed: () {
controller.generateDesktopProject(context);
},
text: '创建项目',
size: 30,
shape: GFButtonShape.square,
fullWidthButton: true,
Container(
padding: const EdgeInsets.all(20),
alignment: Alignment.topRight,
child: Click(
child: const Icon(Icons.settings),
onClick: () {
controller.setFlutterPath(context);
}),
),
Obx(() => Text(controller.log.value))
],
),
routeController: controller.rc,
Expand Down
2 changes: 1 addition & 1 deletion macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.11'
platform :osx, '10.13'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ SPEC CHECKSUMS:
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
PODFILE CHECKSUM: a884f6dd3f7494f3892ee6c81feea3a3abbf9153

COCOAPODS: 1.10.1
COCOAPODS: 1.11.3
6 changes: 3 additions & 3 deletions macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -483,7 +483,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -530,7 +530,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down

0 comments on commit cd9087a

Please sign in to comment.