Class: Flr::CodeUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/flr/util/code_util.rb

Overview

代码生成相关的工具类方法

Constant Summary collapse

@@should_support_nullsafety =
nil

Class Method Summary collapse

Class Method Details

.generate__R_FontFamily_class(font_family_config_array, package_name) ⇒ Object

generate__R_FontFamily_class(font_family_config_array, package_name) -> string

根据模板,为 font_family_config_array(字体家族配置数组)生成 _R_FontFamily class 的代码



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/flr/util/code_util.rb', line 627

def self.generate__R_FontFamily_class(font_family_config_array, package_name)

  all_g_AssetResource_property_code = ""

  font_family_config_array.each do |font_family_config|
    all_g_AssetResource_property_code += "\n"

    font_family_name = font_family_config["family"]

    font_family_id = generate_font_family_id(font_family_name)
    font_family_comment = "font family: #{font_family_name}"

    g_AssetResource_property_code = <<-CODE
  /// #{font_family_comment}
  // ignore: non_constant_identifier_names
  final #{font_family_id} = "#{font_family_name}";
    CODE

    all_g_AssetResource_property_code += g_AssetResource_property_code
  end

  code = <<-CODE
/// This `_R_FontFamily` class is generated and contains references to static font asset resources.
// ignore: camel_case_types
class _R_FontFamily {
  const _R_FontFamily();
#{all_g_AssetResource_property_code}
}
  CODE

  return code
end

.generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name, is_package_project_type) ⇒ Object

generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name, is_package_project_type) -> string

根据模板,为 non_svg_image_asset_array(非svg类的图片资产数组)生成 _R_Image_AssetResource class 的代码



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/flr/util/code_util.rb', line 388

def self.generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name, is_package_project_type)

  all_g_AssetResource_property_code = ""

  non_svg_image_asset_array.each do |image_asset|
    all_g_AssetResource_property_code += "\n"
    g_AssetResource_property_code = generate_AssetResource_property(image_asset, non_svg_image_asset_id_dict, package_name, is_package_project_type, Flr::PRIOR_NON_SVG_IMAGE_FILE_TYPE)
    all_g_AssetResource_property_code += g_AssetResource_property_code
  end

  code = <<-CODE
// ignore: camel_case_types
class _R_Image_AssetResource {
  const _R_Image_AssetResource();
#{all_g_AssetResource_property_code}
}
  CODE

  return code
end

.generate__R_Image_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name) ⇒ Object

generate__R_Image_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name) -> string

根据模板,为 non_svg_image_asset_array(非svg类的图片资产数组)生成 _R_Image class 的代码



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/flr/util/code_util.rb', line 463

def self.generate__R_Image_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name)

  all_g_Asset_method_code = ""

  non_svg_image_asset_array.each do |image_asset|
    all_g_Asset_method_code += "\n"

    asset_id = non_svg_image_asset_id_dict[image_asset]
    asset_comment = generate_asset_comment(image_asset, package_name)

    g_Asset_method_code = <<-CODE
  /// #{asset_comment}
  // ignore: non_constant_identifier_names
  AssetImage #{asset_id}() {
return AssetImage(asset.#{asset_id}.keyName);
  }
    CODE

    all_g_Asset_method_code += g_Asset_method_code
  end

  code = <<-CODE
/// This `_R_Image` class is generated and contains references to static non-svg type image asset resources.
// ignore: camel_case_types
class _R_Image {
  const _R_Image();

  final asset = const _R_Image_AssetResource();
#{all_g_Asset_method_code}
}
  CODE

  return code
end

.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name, is_package_project_type) ⇒ Object

generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name, is_package_project_type) -> string

根据模板,为 svg_image_asset_array(svg类的图片资产数组)生成 _R_Svg_AssetResource class 的代码



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/flr/util/code_util.rb', line 413

def self.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name, is_package_project_type)

  all_g_AssetResource_property_code = ""

  svg_image_asset_array.each do |image_asset|
    all_g_AssetResource_property_code += "\n"
    g_AssetResource_property_code = generate_AssetResource_property(image_asset, svg_image_asset_id_dict, package_name, is_package_project_type, Flr::PRIOR_SVG_IMAGE_FILE_TYPE)
    all_g_AssetResource_property_code += g_AssetResource_property_code
  end

  code = <<-CODE
// ignore: camel_case_types
class _R_Svg_AssetResource {
  const _R_Svg_AssetResource();
#{all_g_AssetResource_property_code}
}
  CODE

  return code
end

.generate__R_Svg_class(svg_image_asset_array, svg_image_asset_id_dict, package_name) ⇒ Object

generate__R_Svg_class(svg_image_asset_array, svg_image_asset_id_dict, package_name) -> string

根据模板,为 svg_image_asset_array(svg类的图片资产数组)生成 _R_Svg class 的代码



502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/flr/util/code_util.rb', line 502

def self.generate__R_Svg_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)

  all_g_Asset_method_code = ""

  svg_image_asset_array.each do |image_asset|
    all_g_Asset_method_code += "\n"

    asset_id = svg_image_asset_id_dict[image_asset]
    asset_comment = generate_asset_comment(image_asset, package_name)

    if should_support_nullsafety
      g_Asset_method_code = <<-CODE
  /// #{asset_comment}
  // ignore: non_constant_identifier_names
  AssetSvg #{asset_id}({required double width, required double height}) {
final imageProvider = AssetSvg(asset.#{asset_id}.keyName, width: width, height: height);
return imageProvider;
  }
      CODE
    else
      g_Asset_method_code = <<-CODE
  /// #{asset_comment}
  // ignore: non_constant_identifier_names
  AssetSvg #{asset_id}({@required double width, @required double height}) {
final imageProvider = AssetSvg(asset.#{asset_id}.keyName, width: width, height: height);
return imageProvider;
  }
      CODE
    end

    all_g_Asset_method_code += g_Asset_method_code
  end

  code = <<-CODE
/// This `_R_Svg` class is generated and contains references to static svg type image asset resources.
// ignore: camel_case_types
class _R_Svg {
  const _R_Svg();

  final asset = const _R_Svg_AssetResource();
#{all_g_Asset_method_code}
}
  CODE

  return code
end

.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name, is_package_project_type) ⇒ Object

generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name, is_package_project_typ) -> string

根据模板,为 text_asset_array(文本资产数组)生成 _R_Text_AssetResource class 的代码



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/flr/util/code_util.rb', line 438

def self.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name, is_package_project_type)

  all_g_AssetResource_property_code = ""

  text_asset_array.each do |text_asset|
    all_g_AssetResource_property_code += "\n"
    g_AssetResource_property_code = generate_AssetResource_property(text_asset, text_asset_id_dict, package_name, is_package_project_type, Flr::PRIOR_TEXT_FILE_TYPE)
    all_g_AssetResource_property_code += g_AssetResource_property_code
  end

  code = <<-CODE
// ignore: camel_case_types
class _R_Text_AssetResource {
  const _R_Text_AssetResource();
#{all_g_AssetResource_property_code}
}
  CODE

  return code
end

.generate__R_Text_class(text_asset_array, text_asset_id_dict, package_name) ⇒ Object

generate__R_Text_class(text_asset_array, text_asset_id_dict, package_name) -> string

根据模板,为 text_asset_array(文本资产数组)生成 _R_Text class 的代码



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/flr/util/code_util.rb', line 553

def self.generate__R_Text_class(text_asset_array, text_asset_id_dict, package_name)

  all_g_Asset_method_code = ""

  text_asset_array.each do |text_asset|
    all_g_Asset_method_code += "\n"

    asset_id = text_asset_id_dict[text_asset]
    asset_comment = generate_asset_comment(text_asset, package_name)

    g_Asset_method_code = <<-CODE
  /// #{asset_comment}
  // ignore: non_constant_identifier_names
  Future<String> #{asset_id}() {
final str = rootBundle.loadString(asset.#{asset_id}.keyName);
return str;
  }
    CODE

    all_g_Asset_method_code += g_Asset_method_code
  end

  code = <<-CODE
/// This `_R_Text` class is generated and contains references to static text asset resources.
// ignore: camel_case_types
class _R_Text {
  const _R_Text();

  final asset = const _R_Text_AssetResource();
#{all_g_Asset_method_code}
}
  CODE

  return code
end

.generate_asset_comment(asset, package_name) ⇒ Object

generate_asset_comment (asset, package_name) -> string

为当前asset生成注释

Examples

package_name = “flutter_r_demo”

Example-1

asset = “packages/flutter_r_demo/assets/images/test.png” asset_comment = “asset: lib/assets/images/test.png”

Example-2

asset = “assets/images/test.png” asset_comment = “asset: assets/images/test.png”



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/flr/util/code_util.rb', line 306

def self.generate_asset_comment (asset, package_name)
  packages_prefix = "packages/#{package_name}/"

  if asset =~ /\A#{packages_prefix}/
    # asset: packages/flutter_r_demo/assets/images/test.png
    # to get assetName: assets/images/test.png
    asset_name = asset.dup
    asset_name[packages_prefix] = ""

    asset_comment = "asset: lib/#{asset_name}"
    return asset_comment
  else
    # asset: assets/images/test.png
    # to get assetName: assets/images/test.png
    asset_name = asset.dup

    asset_comment = "asset: #{asset_name}"
    return asset_comment
  end

end

.generate_asset_id(asset, used_asset_id_array, prior_asset_type = ".*") ⇒ Object

generate_asset_id (asset, used_asset_id_array, prior_asset_type) -> string

  • prior_asset_type: 优先的资源类型;默认值为 “.*”,意味当前不存在任何优先的资源类型

    对于优先的资源类型,其 asset_id 不会携带类型信息,详细见例子
    

为当前 asset 生成 asset_id(资产ID);asset_id 一般为 asset 的 file_basename_no_extension; 但是为了保证 asset_id 的健壮性,需要对 file_basename_no_extension 做以下加工处理:

  • 处理非法字符:把除了字母(a-z, A-Z)、数字(0-9)、‘_’ 字符、‘$’ 字符之外的字符转换为 ‘_’ 字符

  • 首字母转化为小写

  • 处理首字符异常情况:检测首字符是不是数字、‘_’、‘$’,若是则添加前缀字符“a”

  • 处理 asset_id 重名的情况

Examples

Example-1

asset = “packages/flutter_r_demo/assets/images/test.png” asset = “packages/flutter_r_demo/assets/images/test.jpg” used_asset_id_array = [] prior_asset_type = “.png” asset_id = “test”

Example-2

asset = “packages/flutter_r_demo/assets/images/test.jpg” used_asset_id_array = [test] prior_asset_type = “.png” asset_id = “test_jpg”

Example-3

asset = “packages/flutter_r_demo/assets/home-images/test.jpg” used_asset_id_array = [test, test_jpg] prior_asset_type = “.png” asset_id = “test_jpg_1”

Example-4

asset = “packages/flutter_r_demo/assets/texts/test.json” used_asset_id_array = [] prior_asset_type = “.*” asset_id = “test_json”



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/flr/util/code_util.rb', line 241

def self.generate_asset_id(asset, used_asset_id_array, prior_asset_type = ".*")
  file_extname = File.extname(asset).downcase

  dirname = File.dirname(asset)
  parent_dir_name = File.basename(dirname)
  file_basename = File.basename(asset)

  file_basename_no_extension = File.basename(asset, ".*")
  asset_id = file_basename_no_extension.dup
  if prior_asset_type.eql?(".*") or file_extname.eql?(prior_asset_type) == false
    ext_info = file_extname
    ext_info[0] = "_"
    asset_id = asset_id + ext_info
  end

  # 处理非法字符
  asset_id = asset_id.gsub(/[^a-zA-Z0-9_$]/, "_")

  # 首字母转化为小写
  capital = asset_id[0].downcase
  asset_id[0] = capital

  # 处理首字符异常情况
  if capital =~ /[0-9_$]/
    asset_id = "a" + asset_id
  end

  # 处理 asset_id 重名的情况
  if used_asset_id_array.include?(asset_id)
    # 当前asset_id重名次数,初始值为1
    repeat_count = 1

    # 查找当前asset_id衍生出来的asset_id_brother(id兄弟)
    # asset_id_brother = #{asset_id}$#{repeat_count}
    # 其中,repeat_count >= 1
    #
    # Example:
    # asset_id = test
    # asset_id_brother = test$1
    #
    id_brother_regx = /^#{asset_id}\$[1-9][0-9]*$/
    cur_asset_id_brothers = used_asset_id_array.select{ |id| id =~ id_brother_regx }

    repeat_count += cur_asset_id_brothers.size
    asset_id = "#{asset_id}$#{repeat_count}"
  end

  return asset_id
end

.generate_AssetResource_class(package_name) ⇒ Object

generate_AssetResource_class(package_name) -> string

根据模板生成 AssetResource class 的代码



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/flr/util/code_util.rb', line 89

def self.generate_AssetResource_class(package_name)
  code = <<-CODE
/// Asset resource’s metadata class.
/// For example, here is the metadata of `packages/flutter_demo/assets/images/example.png` asset:
/// - packageName:flutter_demo
/// - assetName:assets/images/example.png
/// - fileDirname:assets/images
/// - fileBasename:example.png
/// - fileBasenameNoExtension:example
/// - fileExtname:.png
  CODE

  if should_support_nullsafety
    code += <<-CODE
class AssetResource {
  /// Creates an object to hold the asset resource’s metadata.
  const AssetResource(this.assetName, {this.packageName});

  /// The name of the main asset from the set of asset resources to choose from.
  final String assetName;

  /// The name of the package from which the asset resource is included.
  final String? packageName;

  /// The name used to generate the key to obtain the asset resource. For local assets
  /// this is [assetName], and for assets from packages the [assetName] is
  /// prefixed 'packages/<package_name>/'.
  String get keyName => packageName == null ? assetName : "packages/$packageName/$assetName";

  /// The file basename of the asset resource.
  String get fileBasename {
final basename = path.basename(assetName);
return basename;
  }

  /// The no extension file basename of the asset resource.
  String get fileBasenameNoExtension {
final basenameWithoutExtension = path.basenameWithoutExtension(assetName);
return basenameWithoutExtension;
  }

  /// The file extension name of the asset resource.
  String get fileExtname {
final extension = path.extension(assetName);
return extension;
  }

  /// The directory path name of the asset resource.
  String get fileDirname {
var dirname = assetName;
if (packageName != null) {
  final packageStr = "packages/$packageName/";
  dirname = dirname.replaceAll(packageStr, "");
}
final filenameStr = "$fileBasename/";
dirname = dirname.replaceAll(filenameStr, "");
return dirname;
  }
}
    CODE
  else
    code += <<-CODE
class AssetResource {
  /// Creates an object to hold the asset resource’s metadata.
  const AssetResource(this.assetName, {this.packageName}) : assert(assetName != null);

  /// The name of the main asset from the set of asset resources to choose from.
  final String assetName;

  /// The name of the package from which the asset resource is included.
  final String packageName;

  /// The name used to generate the key to obtain the asset resource. For local assets
  /// this is [assetName], and for assets from packages the [assetName] is
  /// prefixed 'packages/<package_name>/'.
  String get keyName => packageName == null ? assetName : "packages/$packageName/$assetName";

  /// The file basename of the asset resource.
  String get fileBasename {
final basename = path.basename(assetName);
return basename;
  }

  /// The no extension file basename of the asset resource.
  String get fileBasenameNoExtension {
final basenameWithoutExtension = path.basenameWithoutExtension(assetName);
return basenameWithoutExtension;
  }

  /// The file extension name of the asset resource.
  String get fileExtname {
final extension = path.extension(assetName);
return extension;
  }

  /// The directory path name of the asset resource.
  String get fileDirname {
var dirname = assetName;
if (packageName != null) {
  final packageStr = "packages/$packageName/";
  dirname = dirname.replaceAll(packageStr, "");
}
final filenameStr = "$fileBasename/";
dirname = dirname.replaceAll(filenameStr, "");
return dirname;
  }
}
    CODE
  end

  return code
end

.generate_AssetResource_property(asset, asset_id_dict, package_name, is_package_project_type, prior_asset_type = ".*") ⇒ Object

generate_AssetResource_property(asset, asset_id_dict, package_name, is_package_project_type, prior_asset_type) -> string

为当前 asset 生成 AssetResource property 的代码



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/flr/util/code_util.rb', line 332

def self.generate_AssetResource_property(asset, asset_id_dict, package_name, is_package_project_type, prior_asset_type = ".*")
  asset_id = asset_id_dict[asset]
  asset_comment = generate_asset_comment(asset, package_name)

  asset_name = ""
  needPackage = false

  packages_prefix = "packages/#{package_name}/"
  if asset =~ /\A#{packages_prefix}/
    # asset: packages/flutter_r_demo/assets/images/test.png
    # to get asset_name: assets/images/test.png
    asset_name = asset.dup
    asset_name[packages_prefix] = ""

    needPackage = true
  else
    # asset: assets/images/test.png
    # to get asset_name: assets/images/test.png
    asset_name = asset.dup

    if is_package_project_type
      needPackage = true
    else
      needPackage = false
    end

  end

  # 对字符串中的 '$' 进行转义处理:'$' -> '\$'
  # asset_name: assets/images/test$.png
  # to get escaped_asset_name: assets/images/test\$.png
  escaped_asset_name = asset_name.gsub(/[$]/, "\\$")

  if needPackage
    code = <<-CODE
  /// #{asset_comment}
  // ignore: non_constant_identifier_names
  final #{asset_id} = const AssetResource("#{escaped_asset_name}", packageName: R.package);
    CODE

    return code
  else
    code = <<-CODE
  /// #{asset_comment}
  // ignore: non_constant_identifier_names
  final #{asset_id} = const AssetResource("#{escaped_asset_name}", packageName: null);
    CODE

    return code
  end
end

.generate_font_family_id(font_family_name) ⇒ Object

generate_font_family_id(font_family_name) -> string

为当前 font_family_name 生成 font_family_id;font_family_id 一般为 asset 的 font_family_name; 但是为了保证 font_family_id 的健壮性,需要对 font_family_name 做以下加工处理:

  • 处理非法字符:把除了字母(a-z, A-Z)、数字(0-9)、‘_’ 字符、‘$’ 字符之外的字符转换为 ‘_’ 字符

  • 首字母转化为小写

  • 处理首字符异常情况:检测首字符是不是数字、‘_’、‘$’,若是则添加前缀字符“a”

Examples

a_font_family_name = “Amiri” b_font_family_name = “Baloo-Thambi-2” a_font_family_id = “amiri” b_font_family_id = “baloo_Thambi_2”



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/flr/util/code_util.rb', line 604

def self.generate_font_family_id(font_family_name)

  font_family_id = font_family_name.dup

  # 处理非法字符
  font_family_id = font_family_id.gsub(/[^a-zA-Z0-9_$]/, "_")

  # 首字母转化为小写
  capital = font_family_id[0].downcase
  font_family_id[0] = capital

  # 处理首字符异常情况
  if capital =~ /[0-9_$]/
    font_family_id = "a" + font_family_id
  end

  return font_family_id
end

.generate_R_class(package_name) ⇒ Object

generate_R_class(package_name) -> string

根据模板生成 R class 的代码



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/flr/util/code_util.rb', line 42

def self.generate_R_class(package_name)
  code = <<-CODE
// IT IS GENERATED BY FLR - DO NOT MODIFY BY HAND
// YOU CAN GET MORE DETAILS ABOUT FLR FROM:
// - https://github.com/Fly-Mix/flr-cli
// - https://github.com/Fly-Mix/flr-vscode-extension
// - https://github.com/Fly-Mix/flr-as-plugin
//

// ignore: unused_import
import 'package:flutter/widgets.dart';
// ignore: unused_import
import 'package:flutter/services.dart' show rootBundle;
// ignore: unused_import
import 'package:path/path.dart' as path;
// ignore: unused_import
import 'package:flutter_svg/flutter_svg.dart';
// ignore: unused_import
import 'package:r_dart_library/asset_svg.dart';

/// This `R` class is generated and contains references to static asset resources.
class R {
  /// package name: #{package_name}
  static const package = "#{package_name}";

  /// This `R.image` struct is generated, and contains static references to static non-svg type image asset resources.
  static const image = _R_Image();

  /// This `R.svg` struct is generated, and contains static references to static svg type image asset resources.
  static const svg = _R_Svg();

  /// This `R.text` struct is generated, and contains static references to static text asset resources.
  static const text = _R_Text();

  /// This `R.fontFamily` struct is generated, and contains static references to static font asset resources.
  static const fontFamily = _R_FontFamily();
}
  CODE

  return code
end

.should_support_nullsafetyObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flr/util/code_util.rb', line 10

def self.should_support_nullsafety
  if @@should_support_nullsafety != nil
    return @@should_support_nullsafety
  end

  # $ flutter --version
  # Flutter 1.12.13+hotfix.5 • channel stable • https://github.com/flutter/flutter.git
  # Framework • revision 27321ebbad (5 weeks ago) • 2019-12-10 18:15:01 -0800
  # Engine • revision 2994f7e1e6
  # Tools • Dart 2.7.0
  flutter_version_result = `flutter --version`
  if (flutter_version_result.nil? == true || flutter_version_result.empty? == true)
    @@should_support_nullsafety = false
    return @@should_support_nullsafety
  end

  dart_version_str = flutter_version_result.split("Dart")[1]
  dart_version_str.strip!

  if Version.new(dart_version_str) >= Version.new("2.12.0")
    @@should_support_nullsafety = true
    return @@should_support_nullsafety
  end

  @@should_support_nullsafety = false
  return @@should_support_nullsafety
end