Generate asset.dart At VSCode 's Regex
We can write following code to create Image Widget In Flutter
return Image.asset("assets/images/food_purple_chocolate_dessert.jpg");
but, It is difficult to prove this code is corrent.
because "assets/images/food_purple_chocolate_dessert.jpg" may be not found .
So, Generate a Code, it mechanically at Regex
like following.
const images_food_purple_chocolate_dessert_jpg = 'assets/images/food_purple_chocolate_dessert.jpg';
and use
return Image.asset(assets.images_food_purple_chocolate_dessert_jpg);
[ps]: In the future, VSCode's Flutter plug-in or will be discovered at compile time, so this is only know-how for now.
(1) List assets image
:myapp kyorohiro$ find ./assets
./assets/
./assets/.DS_Store
./assets/images
./assets/images/food_pizza_slice_fast.jpg
./assets/images/food_dim_sum_squid.jpg
./assets/images/food_chili_cheese_bowls.jpg
./assets/images/flower_orange_calendula_bright_0.jpg
./assets/images/food_pasta_tomato_theme.jpg
./assets/images/food_purple_chocolate_dessert.jpg
:myapp kyorohiro$
(2)Creaet assets.dart
./assets/images/food_pizza_slice_fast.jpg
./assets/images/food_dim_sum_squid.jpg
./assets/images/food_chili_cheese_bowls.jpg
./assets/images/flower_orange_calendula_bright_0.jpg
./assets/images/food_pasta_tomato_theme.jpg
./assets/images/food_purple_chocolate_dessert.jpg
(3) Erase "./"
erase "./" at vscode regex
find: "\.\/" , replace: ""
assets/images/food_pizza_slice_fast.jpg
assets/images/food_dim_sum_squid.jpg
assets/images/food_chili_cheese_bowls.jpg
assets/images/flower_orange_calendula_bright_0.jpg
assets/images/food_pasta_tomato_theme.jpg
assets/images/food_purple_chocolate_dessert.jpg
(4) Convert into varable
find: "(.*)" , replace: "$1 = '$1'"
assets/images/food_pizza_slice_fast.jpg = 'assets/images/food_pizza_slice_fast.jpg'
assets/images/food_dim_sum_squid.jpg = 'assets/images/food_dim_sum_squid.jpg'
assets/images/food_chili_cheese_bowls.jpg = 'assets/images/food_chili_cheese_bowls.jpg'
assets/images/flower_orange_calendula_bright_0.jpg = 'assets/images/flower_orange_calendula_bright_0.jpg'
assets/images/food_pasta_tomato_theme.jpg = 'assets/images/food_pasta_tomato_theme.jpg'
assets/images/food_purple_chocolate_dessert.jpg = 'assets/images/food_purple_chocolate_dessert.jpg'
= ''
(5) "/" and "." into "_"
find: "(.*)/(.*) = (.*)" , replace: "$1_$2 = $3"
find: "(.*)\.(.*) = (.*)" , replace: "const $1;"
assets_images_food_pizza_slice_fast_jpg = 'assets/images/food_pizza_slice_fast.jpg'
assets_images_food_dim_sum_squid_jpg = 'assets/images/food_dim_sum_squid.jpg'
assets_images_food_chili_cheese_bowls_jpg = 'assets/images/food_chili_cheese_bowls.jpg'
assets_images_flower_orange_calendula_bright_0_jpg = 'assets/images/flower_orange_calendula_bright_0.jpg'
assets_images_food_pasta_tomato_theme_jpg = 'assets/images/food_pasta_tomato_theme.jpg'
assets_images_food_purple_chocolate_dessert_jpg = 'assets/images/food_purple_chocolate_dessert.jpg'
= ''
Add "Const" and ";"
find: "^(.*)$" , replace: "const $1;"
const assets_images_food_pizza_slice_fast_jpg = 'assets/images/food_pizza_slice_fast.jpg';
const assets_images_food_dim_sum_squid_jpg = 'assets/images/food_dim_sum_squid.jpg';
const assets_images_food_chili_cheese_bowls_jpg = 'assets/images/food_chili_cheese_bowls.jpg';
const assets_images_flower_orange_calendula_bright_0_jpg = 'assets/images/flower_orange_calendula_bright_0.jpg';
const assets_images_food_pasta_tomato_theme_jpg = 'assets/images/food_pasta_tomato_theme.jpg';
const assets_images_food_purple_chocolate_dessert_jpg = 'assets/images/food_purple_chocolate_dessert.jpg';
PS
this know-how is from following live coding.
https://dev.to/kyorohiro/todo-dart-x-flutter-mokumoku-live-coding-12-09-2020-bbm
and code and live coding url
https://www.youtube.com/watch?v=meWE25TzQHo&list=PLWfoegDu8aWEod96swhiuzUiFLNo8Lra4&index=4&t=2540s
Top comments (0)