删除 _fix_pause_stop.py
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
import sys
|
||||
|
||||
path = r'C:\Users\jsmbz\Documents\flutter-app-02\lib\features\home\presentation\widgets\map\testmap_pages.dart'
|
||||
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
print(f'Total lines: {len(lines)}')
|
||||
|
||||
# Find lines with "无可用任务"
|
||||
target_lines = []
|
||||
for i, line in enumerate(lines):
|
||||
if '无可用任务' in line:
|
||||
target_lines.append(i)
|
||||
# Print surrounding context
|
||||
start = max(0, i-5)
|
||||
end = min(len(lines), i+3)
|
||||
for j in range(start, end):
|
||||
print(f' L{j+1}: {lines[j].rstrip()}')
|
||||
|
||||
print(f'Found at lines: {[l+1 for l in target_lines]}')
|
||||
|
||||
# For each occurrence, replace the block:
|
||||
# lines[i-3]: " final taskId = taskCubit.state.currentTaskId;"
|
||||
# lines[i-2]: " if (taskId == null) {"
|
||||
# lines[i-1]: " _showPageToast(message: "无可用任务", type: ToastType.warn);"
|
||||
# lines[i]: " return;"
|
||||
# lines[i+1]: " }"
|
||||
|
||||
for line_idx in target_lines:
|
||||
# Find the start of the block
|
||||
block_start = line_idx - 1
|
||||
block_end = line_idx + 2
|
||||
|
||||
indent = ''
|
||||
for ch in lines[block_start]:
|
||||
if ch in (' ', '\t'):
|
||||
indent += ch
|
||||
else:
|
||||
break
|
||||
|
||||
new_lines = [
|
||||
f'{indent}if (taskId == null) {{\n',
|
||||
f'{indent} await taskCubit.fetchAndFilterTask(deviceId);\n',
|
||||
f'{indent} final tasks = taskCubit.state.activeTasks;\n',
|
||||
f'{indent} if (tasks.isNotEmpty) {{\n',
|
||||
f'{indent} taskCubit.selectTask(tasks.first);\n',
|
||||
f'{indent} taskId = tasks.first.id;\n',
|
||||
f'{indent} }} else {{\n',
|
||||
f'{indent} _showPageToast(message: "无可用任务", type: ToastType.warn);\n',
|
||||
f'{indent} return;\n',
|
||||
f'{indent} }}\n',
|
||||
f'{indent}}}\n',
|
||||
]
|
||||
|
||||
# Also change "final taskId" to "var taskId"
|
||||
var_line_idx = line_idx - 2
|
||||
old_var_line = lines[var_line_idx]
|
||||
lines[var_line_idx] = old_var_line.replace('final taskId', 'var taskId')
|
||||
|
||||
# Replace the block
|
||||
old_block = lines[block_start:block_end+1]
|
||||
print(f'Replacing lines {block_start+1}-{block_end+1}:')
|
||||
for l in old_block:
|
||||
print(f' OLD: {l.rstrip()}')
|
||||
for l in new_lines:
|
||||
print(f' NEW: {l.rstrip()}')
|
||||
|
||||
lines[block_start:block_end+1] = new_lines
|
||||
|
||||
with open(path, 'w', encoding='utf-8', newline='') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
print('DONE')
|
||||
Reference in New Issue
Block a user