Flutter
๋ง์ดํฌ๋ก ํ๋ ์์ํฌ
ํ๋์ ์ธ ์ฑ์ ์ํ
Flutter ์ฑ์ ๊ตฌ์ถํ๊ธฐ ์ํ ๊ฒฌ๊ณ ํ ๊ธฐ๋ฐ. ๋ผ์ฐํ , ์ํ ๊ด๋ฆฌ, ๋คํธ์ํน ๋ฑ ๋ชจ๋ ๊ฒ์ด ํ๋์ ์ฐ์ํ ํจํค์ง์.
๊ตฌ์ถ์ ํ์ํ ๋ชจ๋ ๊ฒ
Nylo๋ ํ๋ก๋์ ์์ค์ Flutter ์ ํ๋ฆฌ์ผ์ด์ ์ ์์ ์๊ฒ ๋ง๋๋ ๋ฐ ํ์ํ ๋ชจ๋ ๋๊ตฌ๋ฅผ ์ ๊ณตํฉ๋๋ค.
๋ผ์ฐํ
๋ผ์ฐํธ ๊ฐ๋, ๋งค๊ฐ๋ณ์, ๋ฅ ๋งํน์ ์ง์ํ๋ ๊ฐ๋จํ๊ณ ์ ์ธ์ ์ธ ๋ผ์ฐํ .
์ํ ๊ด๋ฆฌ
์ปจํธ๋กค๋ฌ์ ๊ฐํธํ ์ํ ์ ์ง๋ฅผ ๊ฐ์ถ ๋ด์ฅ ๋ฐ์ํ ์ํ ๊ด๋ฆฌ.
๋คํธ์ํน
์๋ ๋ชจ๋ธ ์ง๋ ฌํ์ ์ธํฐ์ ํฐ๋ฅผ ๊ฐ์ถ ์ฐ์ํ API ์๋น์ค ํด๋์ค.
ํผ
์ ํจ์ฑ ๊ฒ์ฌ, ์บ์คํ , ์๋ ๋ฐ์ดํฐ ๋ฐ์ธ๋ฉ์ ๊ฐ์ถ ๊ฐ๋ ฅํ ํผ ์ฒ๋ฆฌ.
์ธ์ฆ
๋ผ์ฐํธ ๊ฐ๋, ํ ํฐ ์ ์ฅ, ์ธ์ ๊ด๋ฆฌ๋ฅผ ํตํ ์์ ํ ์ธ์ฆ.
Metro CLI
๊ฐ๋ ฅํ CLI ๋ช ๋ น์ผ๋ก ํ์ด์ง, ๋ชจ๋ธ, ์ปจํธ๋กค๋ฌ ๋ฑ์ ์์ฑํ์ธ์.
ํฐ๋ฏธ๋์์ ๋ฌด์์ด๋ ์์ฑ
Metro๋ ๋จ์ผ ๋ช ๋ น์ผ๋ก ํ์ด์ง, ๋ชจ๋ธ, ์ปจํธ๋กค๋ฌ, ์์ ฏ ๋ฑ์ ์ค์บํด๋ฉํ๋ Nylo์ CLI ๋๊ตฌ์ ๋๋ค.
Metro์ ๋ํด ๋ ์์๋ณด๊ธฐmetro make:page HomePage
# Creates a new page called HomePage
metro make:api_service User
# Creates a new API Service called UserApiService
metro make:model User
# Creates a new model called User
metro make:stateful_widget FavouriteWidget
# Creates a new stateful widget called FavouriteWidget
class ApiService extends NyApiService {
@override
String get baseUrl => "https://api.example.com/v1";
Future<List<Post>> posts() async {
return await network(
request: (request) => request.get("/posts"),
);
}
}
// Usage in your page
final posts = await api<ApiService>((request) => request.posts());
๊ฐํธํ API ํตํฉ
์๋ JSON ํ์ฑ, ์ค๋ฅ ์ฒ๋ฆฌ, ์์ฒญ ์ธํฐ์ ํฐ๋ฅผ ๊ฐ์ถ ๊น๋ํ๊ณ ์ ์ง๋ณด์ ๊ฐ๋ฅํ API ์๋น์ค๋ฅผ ์์ฑํ์ธ์.
๋คํธ์ํน์ ๋ํด ๋ ์์๋ณด๊ธฐ์ ์์ ์ํ ๊ฐ๋ ฅํ ๋๊ตฌ
๋ค์ Flutter ์ฑ์ ๊ตฌ์ถํ๋ ๋ฐ ํ์ํ ๋ชจ๋ ๊ฒ
appRouter() => nyRoutes((router) {
router.add(HomePage.path).initialRoute();
router.add(DiscoverPage.path);
router.add(LoginPage.path,
transitionType: TransitionType.bottomToTop());
router.add(ProfilePage.path,
routeGuard: [
AuthGuard()
]
);
});
Flutter ์ ํ๋ฆฌ์ผ์ด์ ์ ์ํ ๋ณต์กํ ๋ผ์ฐํธ, ์ธํฐํ์ด์ค ๋ฐ UI ํ์ด์ง๋ฅผ ๊ตฌ์ถํ์ธ์.
๋ ์์๋ณด๊ธฐ
์ฌ์ฉ์ ์ธ์ฆ
String userToken = "eyJhbG123...";
await Auth.authenticate(data: {"token": userToken});
์ด์ ์ฌ์ฉ์๊ฐ ์ฑ์ ์ด๋ฉด ์ธ์ฆ๋ฉ๋๋ค.
final userData = Auth.data();
// {"token": "eyJhbG123..."}
bool isAuthenticated = await Auth.isAuthenticated();
// true
๋ผ์ฐํฐ์ authenticatedRoute๋ฅผ ์ค์ ํ๋ค๋ฉด, ์ฌ์ฉ์๊ฐ ์ฑ์ ๋ค์ ์ด ๋ ์ด ํ์ด์ง๊ฐ ํ์๋ฉ๋๋ค.
appRouter() => nyRoutes((router) {
...
router.add(LandingPage.path).initialRoute();
router.add(DashboardPage.path).authenticatedRoute();
// overrides the initial route when a user is authenticated
์ฌ์ฉ์ ๋ก๊ทธ์์
await Auth.logout();
Flutter ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉ์๋ฅผ ์ธ์ฆํ์ธ์.
๋ ์์๋ณด๊ธฐ
ํผ ์์ฑ
metro make:form RegisterForm
ํผ ์์
class RegisterForm extends NyFormWidget {
RegisterForm({super.key, super.submitButton, super.onSubmit, super.onFailure});
// Add your fields here
@override
fields() => [
Field.capitalizeWords("name",
label: "Name",
validator: FormValidator.notEmpty(),
),
Field.email("email_address",
label: "Email",
validator: FormValidator.email()
),
Field.password("password",
label: "Password",
validator: FormValidator.password(),
),
];
static NyFormActions get actions => const NyFormActions("RegisterForm");
}
์์ ฏ์์ ํผ ์ฌ์ฉ
@override
Widget build(BuildContext context) {
return Scaffold(
body: RegisterForm(
submitButton: Button.primary(text: "Submit"),
onSubmit: (data) {
printInfo(data);
},
),
);
}
Nylo ํผ์ผ๋ก ํ ๊ณณ์์ ๋ฐ์ดํฐ๋ฅผ ๊ด๋ฆฌ, ๊ฒ์ฆ, ์ ์ถํ์ธ์.
๋ ์์๋ณด๊ธฐ
์ํ ๊ด๋ฆฌ ์์ ฏ ์์ฑ
metro make:stateful_widget CartIcon
class _CartIconState extends NyState<CartIcon> {
...
@override
Map<String, Function> get stateActions => {
"clear_cart": () {
_items = 0;
},
...
};
@override
Widget view(BuildContext context) {
return Container(child: Text("Items in cart: ${_items}"));
}
}
Use CartIcon.action("clear_cart")
Button.primary(text: "Add to cart",
onPressed: () {
CartIcon.action("clear_cart");
}
)
Flutter ์ ํ๋ฆฌ์ผ์ด์ ์ ์์ ฏ์ ์ํ ๊ฐ๋ ฅํ ์ํ ๊ด๋ฆฌ.
๋ ์์๋ณด๊ธฐ
์ด๋ฒคํธ ์์ฑ
metro make:event Logout
class LogoutEvent implements NyEvent {
@override
final listeners = {
DefaultListener: DefaultListener(),
};
}
class DefaultListener extends NyListener {
@override
handle(dynamic event) async {
// logout user
await Auth.logout();
// redirect to home page
routeTo(HomePage.path,
navigationType: NavigationType.pushAndForgetAll
);
}
}
์ด๋ฒคํธ ๋ฐํ
MaterialButton(child: Text("Logout"),
onPressed: () {
event<LogoutEvent>();
},
)
์ ํ๋ฆฌ์ผ์ด์ ์์ ์ด๋ฒคํธ๋ฅผ ๋ฐํํ๊ณ ์์ ํ์ธ์.
๋ ์์๋ณด๊ธฐ
์์ ์ ํ ๋ฒ ์คํํ๋๋ก ์์ฝ
Nylo.scheduleOnce("onboarding_info", () {
print("Perform code here to run once");
});
ํน์ ๋ ์ง ์ดํ์ ์์ ์ ํ ๋ฒ ์คํํ๋๋ก ์์ฝ
Nylo.scheduleOnceAfterDate("app_review_rating", () {
print("Perform code to run once after DateTime(2025, 04, 10)");
}, date: DateTime(2025, 04, 10));
์์ ์ ๋งค์ผ ํ ๋ฒ ์คํํ๋๋ก ์์ฝ
Nylo.scheduleOnceDaily("free_daily_coins", () {
print("Perform code to run once daily");
});
Flutter ์ ํ๋ฆฌ์ผ์ด์ ์์ ์์ ์ ํ ๋ฒ ๋๋ ๋งค์ผ ์คํํ๋๋ก ์์ฝํ์ธ์.
๋ ์์๋ณด๊ธฐ
API ์๋น์ค ์์ฑ
metro make:api_service User
class UserApiService extends NyApiService {
@override
String get baseUrl => getEnv("API_BASE_URL");
Future<User?> fetchUser(int id) async {
return await get<User>(
"/users/$id",
queryParameters: {"include": "profile"},
);
}
Future<User?> createUser(Map<String, dynamic> data) async {
return await post<User>("/users", data: data);
}
}
ํ์ด์ง์์ API ํธ์ถ
User? user = await api<UserApiService>(
(request) => request.fetchUser(1),
);
์๋ JSON ํ์ฑ, ์บ์ฑ, ์ธํฐ์ ํฐ๋ฅผ ๊ฐ์ถ ์ฐ์ํ API ์๋น์ค.
๋ ์์๋ณด๊ธฐ
๋ฐ์ดํฐ๋ฅผ ์์ ํ๊ฒ ์ ์ฅ
// Save values to secure storage
await NyStorage.save("coins", 100);
await NyStorage.save("username", "Anthony");
await NyStorage.save("isPremium", true);
// Save with TTL (auto-expires)
await NyStorage.save("session", "abc123",
expiry: Duration(hours: 1),
);
ํ์ ์บ์คํ ์ผ๋ก ์ฝ๊ธฐ
// Automatic type casting
String? username = await NyStorage.read("username");
int? coins = await NyStorage.read<int>("coins");
bool? isPremium = await NyStorage.read<bool>("isPremium");
// Delete a value
await NyStorage.delete("coins");
ํ์ ์บ์คํ , TTL ๋ง๋ฃ, ์ปฌ๋ ์ ์ ๊ฐ์ถ ์์ ํ ๋ก์ปฌ ์คํ ๋ฆฌ์ง.
๋ ์์๋ณด๊ธฐ
์ธ์ด ํ์ผ ์ถ๊ฐ
{
"welcome": "Welcome",
"greeting": "Hello {{name}}",
"navigation": {
"home": "Home",
"profile": "Profile"
}
}
์์ ฏ์์ ํ ์คํธ ๋ฒ์ญ
// Simple translation
Text("welcome".tr()) // "Welcome"
// With arguments
Text("greeting".tr(arguments: {"name": "Anthony"}))
// "Hello Anthony"
// Nested keys
Text("navigation.home".tr()) // "Home"
JSON ํ์ผ, ์ธ์, RTL์ ์ง์ํ๋ ๋ค๊ตญ์ด ์ง์.
๋ ์์๋ณด๊ธฐ
๋ด๋น๊ฒ์ด์ ํ๋ธ ์์ฑ
metro make:navigation_hub base
class _BaseNavigationHubState extends NavigationHub<BaseNavigationHub> {
NavigationHubLayout? layout = NavigationHubLayout.bottomNav();
@override
bool get maintainState => true;
_BaseNavigationHubState() : super(() async {
return {
0: NavigationTab(
title: "Home",
page: HomeTab(),
icon: Icon(Icons.home),
),
1: NavigationTab(
title: "Settings",
page: SettingsTab(),
icon: Icon(Icons.settings),
),
};
});
}
๋ ์ด์์์ ์ฝ๊ฒ ์ ํ
// Bottom navigation
NavigationHubLayout.bottomNav()
// Top navigation
NavigationHubLayout.topNav()
// Journey / wizard flow
NavigationHubLayout.journey()
์ํ ์ ์ง์ ํจ๊ป ํ๋จ ๋ด๋น๊ฒ์ด์ , ์๋จ ๋ด๋น๊ฒ์ด์ ๋๋ ์ฌ์ ํ๋ฆ์ ๊ตฌ์ถํ์ธ์.
๋ ์์๋ณด๊ธฐ
I'm new to Dart and new to your framework (which I love)
Peter Senior Director of Heroku Global
I wanted to thank you guys for the great job you are doing.
@youssefKadaouiAbbassi
Just to say that I am in love with @nylo_dev's website!! Definitely gonna explore it!
@esfoliante_txt
Really love the concept of this framework
@Chrisvidal
Nylo is the best framework for flutter, which makes developing easy
@higakijin
This is incredible. Very well done!
FireflyDaniel
Very nice Framework! Thank you so much!
@ChaoChao2509
I just discovered this framework and I'm very impressed. Thank you
@lepresk
Great work on Nylo
@dylandamsma
This is by far the best framework out there. Amazing quality and features. Thanks so much.
@2kulfi
It's interesting and very amazing. It makes the work more easier and less time consuming. Great work. Thank you
darkreader01
Salut. Je viens juste de dรฉcouvrir votre outils et je le trouve vraiment super. Une belle dรฉcouverte pour moi ๐๐ค
ojean-01