Flutter ਪ੍ਰੋਟੋਟਾਈਪ ਬਣਾਉਣਾ ਆਸਾਨ ਹੈ। ਇੱਕ ਉਤਪਾਦਨ-ਤਿਆਰ Flutter ਐਪਲੀਕੇਸ਼ਨ ਬਣਾਉਣਾ ਜੋ ਸਕੇਲ ਕਰਦਾ ਹੈ, ਲੋਡ ਦੇ ਹੇਠਾਂ ਵਧੀਆ ਪ੍ਰਦਰਸ਼ਨ ਕਰਦਾ ਹੈ, ਅਤੇ ਸਾਲਾਂ ਤੋਂ ਸੰਭਾਲਣ ਯੋਗ ਹੈ, ਆਰਕੀਟੈਕਚਰ, ਸਟੇਟ ਪ੍ਰਬੰਧਨ, ਟੈਸਟਿੰਗ, ਅਤੇ ਤੈਨਾਤੀ ਵਰਕਫਲੋ ਦੀ ਬਹੁਤ ਡੂੰਘੀ ਸਮਝ ਦੀ ਲੋੜ ਹੈ। ਇਹ ਗਾਈਡ ਟਿਊਟੋਰਿਅਲ ਪ੍ਰੋਜੈਕਟਾਂ ਅਤੇ ਅਸਲ-ਸੰਸਾਰ ਐਪਲੀਕੇਸ਼ਨਾਂ ਵਿਚਕਾਰ ਪਾੜੇ ਨੂੰ ਪੂਰਾ ਕਰਦੀ ਹੈ, ਉਹਨਾਂ ਪੈਟਰਨਾਂ ਅਤੇ ਅਭਿਆਸਾਂ ਨੂੰ ਕਵਰ ਕਰਦੀ ਹੈ ਜਿਨ੍ਹਾਂ 'ਤੇ ਪੇਸ਼ੇਵਰ Flutter ਟੀਮਾਂ ਹਰ ਰੋਜ਼ ਨਿਰਭਰ ਕਰਦੀਆਂ ਹਨ। Flutter
ਲਈ
ਕਲੀਨ ਆਰਕੀਟੈਕਚਰ ਤੁਹਾਡੀ ਐਪਲੀਕੇਸ਼ਨ ਨੂੰ ਸਪੱਸ਼ਟ ਸੀਮਾਵਾਂ ਅਤੇ ਨਿਰਭਰਤਾ ਨਿਯਮਾਂ ਦੇ ਨਾਲ ਵੱਖਰੀਆਂ ਪਰਤਾਂ ਵਿੱਚ ਵੱਖ ਕਰਦਾ ਹੈ। ਇਹ ਵਿਭਾਜਨ ਤੁਹਾਡੇ ਕੋਡ ਨੂੰ ਪਰੀਖਣਯੋਗ, ਰੱਖ-ਰਖਾਅਯੋਗ, ਅਤੇ ਬਾਹਰੀ ਢਾਂਚੇ ਅਤੇ ਸਾਧਨਾਂ ਤੋਂ ਸੁਤੰਤਰ ਬਣਾਉਂਦਾ ਹੈ।ਲੇਅਰ ਸਟ੍ਰਕਚਰ
ਇੱਕ ਪ੍ਰੋਡਕਸ਼ਨ Flutter ਐਪ ਆਮ ਤੌਰ 'ਤੇ ਤਿੰਨ-ਲੇਅਰ ਆਰਕੀਟੈਕਚਰ ਦੀ ਪਾਲਣਾ ਕਰਦਾ ਹੈ:
- ਪ੍ਰਸਤੁਤੀ ਲੇਅਰ- ਵਿਜੇਟਸ, ਪੰਨੇ, ਅਤੇ ਸਥਿਤੀ ਪ੍ਰਬੰਧਨ ਇਹ ਪਰਤ ਡੋਮੇਨ ਪਰਤ 'ਤੇ ਨਿਰਭਰ ਕਰਦੀ ਹੈ ਪਰ ਕਦੇ ਵੀ ਸਿੱਧੇ ਤੌਰ 'ਤੇ ਡਾਟਾ ਸਰੋਤਾਂ 'ਤੇ ਨਹੀਂ।
- ਡੋਮੇਨ ਲੇਅਰ- ਵਪਾਰਕ ਤਰਕ, ਇਕਾਈਆਂ, ਅਤੇ ਵਰਤੋਂ ਦੇ ਮਾਮਲੇ। ਇਸ ਲੇਅਰ ਦੀ Flutter ਜਾਂ ਕਿਸੇ ਬਾਹਰੀ ਪੈਕੇਜਾਂ 'ਤੇ ਜ਼ੀਰੋ ਨਿਰਭਰਤਾ ਹੈ। ਇਹ ਰਿਪੋਜ਼ਟਰੀ ਇੰਟਰਫੇਸ (ਐਬਸਟਰੈਕਟ ਕਲਾਸਾਂ) ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ ਜੋ ਡੇਟਾ ਲੇਅਰ ਲਾਗੂ ਕਰਦਾ ਹੈ।
- ਡਾਟਾ ਲੇਅਰ- ਰਿਪੋਜ਼ਟਰੀ ਲਾਗੂਕਰਨ, API ਕਲਾਇੰਟਸ, ਸਥਾਨਕ ਡਾਟਾਬੇਸ ਪਹੁੰਚ, ਅਤੇ ਡਾਟਾ ਮਾਡਲ (DTOs)। ਇਹ ਲੇਅਰ ਡੋਮੇਨ ਲੇਅਰ ਵਿੱਚ ਪਰਿਭਾਸ਼ਿਤ ਇੰਟਰਫੇਸਾਂ ਨੂੰ ਲਾਗੂ ਕਰਦੀ ਹੈ।
lib/
core/
error/
exceptions.dart
failures.dart
network/
network_info.dart
usecases/
usecase.dart
features/
authentication/
data/
datasources/
auth_remote_datasource.dart
auth_local_datasource.dart
models/
user_model.dart
repositories/
auth_repository_impl.dart
domain/
entities/
user.dart
repositories/
auth_repository.dart
usecases/
login.dart
register.dart
logout.dart
presentation/
bloc/
auth_bloc.dart
auth_event.dart
auth_state.dart
pages/
login_page.dart
register_page.dart
widgets/
login_form.dartਨਿਰਭਰਤਾ ਨਿਯਮ ਸਖਤ ਹੈ: ਅੰਦਰੂਨੀ ਪਰਤਾਂ ਕਦੇ ਵੀ ਬਾਹਰੀ ਪਰਤਾਂ ਬਾਰੇ ਨਹੀਂ ਜਾਣਦੀਆਂ। ਡੋਮੇਨ ਲੇਅਰ ਐਬਸਟਰੈਕਟ ਰਿਪੋਜ਼ਟਰੀ ਇੰਟਰਫੇਸ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦੀ ਹੈ, ਅਤੇ ਡੇਟਾ ਲੇਅਰ ਠੋਸ ਲਾਗੂਕਰਨ ਪ੍ਰਦਾਨ ਕਰਦੀ ਹੈ। ਨਿਯੰਤਰਣ ਦਾ ਇਹ ਉਲਟਾ ਤੁਹਾਨੂੰ ਵਪਾਰਕ ਤਰਕ ਨੂੰ ਛੂਹਣ ਤੋਂ ਬਿਨਾਂ ਡੇਟਾ ਸਰੋਤਾਂ ਨੂੰ ਸਵੈਪ ਕਰਨ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ।
ਰਾਜ ਪ੍ਰਬੰਧਨ: BLoC ਅਤੇ Riverpod
Flutter ਪ੍ਰੋਜੈਕਟ ਵਿੱਚ ਸਹੀ ਰਾਜ ਪ੍ਰਬੰਧਨ ਹੱਲ ਚੁਣਨਾ ਸਭ ਤੋਂ ਪ੍ਰਭਾਵਸ਼ਾਲੀ ਆਰਕੀਟੈਕਚਰਲ ਫੈਸਲਿਆਂ ਵਿੱਚੋਂ ਇੱਕ ਹੈ।
BLoC ਪੈਟਰਨ
BLoC (ਬਿਜ਼ਨਸ ਲਾਜਿਕ ਕੰਪੋਨੈਂਟ) ਸਟੇਟ ਦਾ ਪ੍ਰਬੰਧਨ ਕਰਨ ਲਈ ਸਟ੍ਰੀਮਾਂ ਦੀ ਵਰਤੋਂ ਕਰਦਾ ਹੈ। ਘਟਨਾਵਾਂ ਅੰਦਰ ਆਉਂਦੀਆਂ ਹਨ, ਰਾਜ ਬਾਹਰ ਨਿਕਲਦੇ ਹਨ। ਇਹ ਦਿਸ਼ਾ-ਨਿਰਦੇਸ਼ ਡੇਟਾ ਪ੍ਰਵਾਹ ਰਾਜ ਦੀਆਂ ਤਬਦੀਲੀਆਂ ਨੂੰ ਅਨੁਮਾਨ ਲਗਾਉਣ ਯੋਗ ਅਤੇ ਡੀਬੱਗ ਕਰਨ ਲਈ ਆਸਾਨ ਬਣਾਉਂਦਾ ਹੈ।
// Events
abstract class AuthEvent {}
class LoginRequested extends AuthEvent {
final String email;
final String password;
LoginRequested({required this.email, required this.password});
}
class LogoutRequested extends AuthEvent {}
// States
abstract class AuthState {}
class AuthInitial extends AuthState {}
class AuthLoading extends AuthState {}
class AuthAuthenticated extends AuthState {
final User user;
AuthAuthenticated(this.user);
}
class AuthError extends AuthState {
final String message;
AuthError(this.message);
}
// BLoC
class AuthBloc extends Bloc<AuthEvent, AuthState> {
final LoginUseCase loginUseCase;
final LogoutUseCase logoutUseCase;
AuthBloc({
required this.loginUseCase,
required this.logoutUseCase,
}) : super(AuthInitial()) {
on<LoginRequested>(_onLoginRequested);
on<LogoutRequested>(_onLogoutRequested);
}
Future<void> _onLoginRequested(
LoginRequested event,
Emitter<AuthState> emit,
) async {
emit(AuthLoading());
final result = await loginUseCase(
LoginParams(email: event.email, password: event.password),
);
result.fold(
(failure) => emit(AuthError(failure.message)),
(user) => emit(AuthAuthenticated(user)),
);
}
Future<void> _onLogoutRequested(
LogoutRequested event,
Emitter<AuthState> emit,
) async {
await logoutUseCase();
emit(AuthInitial());
}
}Riverpod
Riverpod ਰਾਜ ਪ੍ਰਬੰਧਨ ਲਈ ਵਧੇਰੇ ਲਚਕਦਾਰ, ਕੰਪਾਇਲ-ਸੁਰੱਖਿਅਤ ਪਹੁੰਚ ਦੀ ਪੇਸ਼ਕਸ਼ ਕਰਦਾ ਹੈ। ਪ੍ਰਦਾਤਾ ਦੇ ਉਲਟ, Riverpod ਵਿਜੇਟ ਟ੍ਰੀ 'ਤੇ ਨਿਰਭਰ ਨਹੀਂ ਕਰਦਾ ਹੈ, ਜਿਸ ਨਾਲ ਜਾਂਚ ਅਤੇ ਰਚਨਾ ਕਰਨਾ ਆਸਾਨ ਹੋ ਜਾਂਦਾ ਹੈ।
// Define providers
final authRepositoryProvider = Provider<AuthRepository>((ref) {
return AuthRepositoryImpl(
remoteDatasource: ref.read(authRemoteDatasourceProvider),
localDatasource: ref.read(authLocalDatasourceProvider),
);
});
final authStateProvider = StateNotifierProvider<AuthNotifier, AuthState>((ref) {
return AuthNotifier(ref.read(authRepositoryProvider));
});
class AuthNotifier extends StateNotifier<AuthState> {
final AuthRepository _repository;
AuthNotifier(this._repository) : super(const AuthState.initial());
Future<void> login(String email, String password) async {
state = const AuthState.loading();
final result = await _repository.login(email, password);
state = result.fold(
(failure) => AuthState.error(failure.message),
(user) => AuthState.authenticated(user),
);
}
}
// Use in widgets
class LoginPage extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final authState = ref.watch(authStateProvider);
return authState.when(
initial: () => LoginForm(),
loading: () => const CircularProgressIndicator(),
authenticated: (user) => HomePage(user: user),
error: (message) => ErrorDisplay(message: message),
);
}
}ਨਿਰਭਰਤਾ ਇੰਜੈਕਸ਼ਨ
ਟੈਸਟ ਯੋਗ ਕੋਡ ਲਈ ਸਹੀ ਨਿਰਭਰਤਾ ਇੰਜੈਕਸ਼ਨ ਜ਼ਰੂਰੀ ਹੈ।get_itਪੈਕੇਜ ਇੱਕ ਸਧਾਰਨ ਸੇਵਾ ਲੋਕੇਟਰ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ ਜੋ ਸਾਫ਼ ਆਰਕੀਟੈਕਚਰ ਨਾਲ ਵਧੀਆ ਕੰਮ ਕਰਦਾ ਹੈ।
final sl = GetIt.instance;
void initDependencies() {
// External
sl.registerLazySingleton(() => Dio()..interceptors.add(AuthInterceptor()));
sl.registerLazySingleton(() => InternetConnectionChecker());
// Data sources
sl.registerLazySingleton<AuthRemoteDatasource>(
() => AuthRemoteDatasourceImpl(dio: sl()),
);
sl.registerLazySingleton<AuthLocalDatasource>(
() => AuthLocalDatasourceImpl(secureStorage: sl()),
);
// Repositories
sl.registerLazySingleton<AuthRepository>(
() => AuthRepositoryImpl(
remoteDatasource: sl(),
localDatasource: sl(),
networkInfo: sl(),
),
);
// Use cases
sl.registerLazySingleton(() => LoginUseCase(sl()));
sl.registerLazySingleton(() => RegisterUseCase(sl()));
// BLoCs
sl.registerFactory(() => AuthBloc(
loginUseCase: sl(),
logoutUseCase: sl(),
));
}API Dio ਨਾਲ ਏਕੀਕਰਣ
Dio ਡਾਰਟ ਲਈ ਸਭ ਤੋਂ ਪ੍ਰਸਿੱਧ HTTP ਕਲਾਇੰਟ ਹੈ, ਇੰਟਰਸੈਪਟਰ, ਗਲੋਬਲ ਕੌਂਫਿਗਰੇਸ਼ਨ ਅਤੇ ਗਲੋਬਲ ਕੌਂਫਿਗਰੇਸ਼ਨ ਲਈ, ਪੇਸ਼ਕਸ਼ ਕਰਦਾ ਹੈ। ਟਾਈਪ-ਸੁਰੱਖਿਅਤ ਬੇਨਤੀ ਅਤੇ ਜਵਾਬ ਪ੍ਰਬੰਧਨ ਨਾਲ ਆਪਣੀ API ਪਰਤ ਨੂੰ ਢਾਂਚਾ ਬਣਾਓ।
class ApiClient {
final Dio _dio;
ApiClient(this._dio) {
_dio.options = BaseOptions(
baseUrl: Environment.apiBaseUrl,
connectTimeout: const Duration(seconds: 10),
receiveTimeout: const Duration(seconds: 15),
headers: {'Content-Type': 'application/json'},
);
_dio.interceptors.addAll([
AuthInterceptor(),
LogInterceptor(requestBody: true, responseBody: true),
RetryInterceptor(dio: _dio, retries: 3),
]);
}
Future<T> get<T>(
String path, {
Map<String, dynamic>? queryParameters,
required T Function(dynamic data) parser,
}) async {
try {
final response = await _dio.get(path, queryParameters: queryParameters);
return parser(response.data);
} on DioException catch (e) {
throw _handleError(e);
}
}
AppException _handleError(DioException error) {
switch (error.type) {
case DioExceptionType.connectionTimeout:
case DioExceptionType.receiveTimeout:
return NetworkException('Connection timed out');
case DioExceptionType.badResponse:
return ServerException(
error.response?.statusCode ?? 500,
error.response?.data?['message'] ?? 'Unknown error',
);
default:
return NetworkException('Network error occurred');
}
}
}Hive ਅਤੇ Sqflite ਨਾਲ ਸਥਾਨਕ ਸਟੋਰੇਜ
ਜ਼ਿਆਦਾਤਰ ਉਤਪਾਦਨ ਐਪਾਂ ਨੂੰ ਸਥਾਨਕ ਡਾਟਾ ਸਥਿਰਤਾ ਦੀ ਲੋੜ ਹੁੰਦੀ ਹੈ। ਆਪਣੀ ਡਾਟਾ ਗੁੰਝਲਤਾ ਦੇ ਆਧਾਰ 'ਤੇ ਸਹੀ ਟੂਲ ਚੁਣੋ। ਮੁੱਖ-ਮੁੱਲ ਅਤੇ ਵਸਤੂ ਸਟੋਰੇਜ ਲਈ
Hive
Hive ਇੱਕ ਹਲਕਾ, ਤੇਜ਼-ਤੇਜ਼ NoSQL ਡੇਟਾਬੇਸ ਹੈ ਜੋ ਸ਼ੁੱਧ ਡਾਰਟ ਵਿੱਚ ਲਿਖਿਆ ਗਿਆ ਹੈ। ਇਹ ਕੈਚਿੰਗ, ਉਪਭੋਗਤਾ ਤਰਜੀਹਾਂ, ਅਤੇ ਛੋਟੇ ਤੋਂ ਦਰਮਿਆਨੇ ਡੇਟਾਸੈਟਾਂ ਨੂੰ ਸਟੋਰ ਕਰਨ ਲਈ ਆਦਰਸ਼ ਹੈ। ਰਿਲੇਸ਼ਨਲ ਡੇਟਾ ਲਈ
@HiveType(typeId: 0)
class CachedArticle extends HiveObject {
@HiveField(0)
final String id;
@HiveField(1)
final String title;
@HiveField(2)
final String content;
@HiveField(3)
final DateTime cachedAt;
CachedArticle({
required this.id,
required this.title,
required this.content,
required this.cachedAt,
});
}
class ArticleCacheService {
static const _boxName = 'articles_cache';
Future<void> cacheArticles(List<Article> articles) async {
final box = await Hive.openBox<CachedArticle>(_boxName);
final cached = articles.map((a) => CachedArticle(
id: a.id,
title: a.title,
content: a.content,
cachedAt: DateTime.now(),
));
await box.clear();
await box.addAll(cached);
}
Future<List<CachedArticle>> getCachedArticles() async {
final box = await Hive.openBox<CachedArticle>(_boxName);
return box.values.toList();
}
}Sqflite
ਜਦੋਂ ਤੁਹਾਡੇ ਡੇਟਾ ਵਿੱਚ ਗੁੰਝਲਦਾਰ ਸਬੰਧ ਹੁੰਦੇ ਹਨ ਅਤੇ ਤੁਹਾਨੂੰ SQL ਸਵਾਲਾਂ ਦੀ ਲੋੜ ਹੁੰਦੀ ਹੈ, ਤਾਂ Sqflite Flutter ਲਈ ਇੱਕ ਪੂਰਾ SQLite ਲਾਗੂਕਰਨ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ। ਇਸ ਨੂੰ ਸਟ੍ਰਕਚਰਡ ਡੇਟਾ ਲਈ ਵਰਤੋ ਜੋ ਜੋੜਾਂ, ਸੂਚਕਾਂਕ ਅਤੇ ਲੈਣ-ਦੇਣ ਤੋਂ ਲਾਭ ਪ੍ਰਾਪਤ ਕਰਦਾ ਹੈ।
ਪੁਸ਼ ਸੂਚਨਾਵਾਂ
ਫਾਇਰਬੇਸ ਕਲਾਊਡ ਮੈਸੇਜਿੰਗ (FCM) ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹੋਏ ਪੁਸ਼ ਸੂਚਨਾਵਾਂ ਨੂੰ ਉਚਿਤ ਅਨੁਮਤੀ ਹੈਂਡਲਿੰਗ ਅਤੇ ਬੈਕਗ੍ਰਾਊਂਡ ਸੰਦੇਸ਼ ਪ੍ਰਕਿਰਿਆ ਦੇ ਨਾਲ ਲਾਗੂ ਕਰੋ।
class NotificationService {
final FirebaseMessaging _messaging = FirebaseMessaging.instance;
Future<void> initialize() async {
// Request permission
final settings = await _messaging.requestPermission(
alert: true,
badge: true,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
// Get FCM token
final token = await _messaging.getToken();
await _sendTokenToServer(token);
// Listen for token refresh
_messaging.onTokenRefresh.listen(_sendTokenToServer);
// Handle foreground messages
FirebaseMessaging.onMessage.listen(_handleForegroundMessage);
// Handle background/terminated message taps
FirebaseMessaging.onMessageOpenedApp.listen(_handleMessageTap);
}
}
void _handleForegroundMessage(RemoteMessage message) {
// Show local notification using flutter_local_notifications
FlutterLocalNotificationsPlugin().show(
message.hashCode,
message.notification?.title,
message.notification?.body,
const NotificationDetails(
android: AndroidNotificationDetails(
'default_channel',
'Default',
importance: Importance.high,
),
),
);
}
}ਡੀਪ ਲਿੰਕਿੰਗ
ਡੀਪ ਲਿੰਕਿੰਗ ਉਪਭੋਗਤਾਵਾਂ ਨੂੰ ਬਾਹਰੀ URL ਤੋਂ ਤੁਹਾਡੀ ਐਪ ਦੇ ਅੰਦਰ ਖਾਸ ਸਮੱਗਰੀ 'ਤੇ ਸਿੱਧਾ ਨੈਵੀਗੇਟ ਕਰਨ ਦੀ ਆਗਿਆ ਦਿੰਦੀ ਹੈ। Flutter ਯੂਆਰਆਈ-ਅਧਾਰਿਤ ਡੂੰਘੇ ਲਿੰਕਾਂ ਅਤੇ ਗਤੀਸ਼ੀਲ ਲਿੰਕਾਂ ਦੋਵਾਂ ਦਾ ਸਮਰਥਨ ਕਰਦਾ ਹੈ।
// Configure in MaterialApp
MaterialApp(
onGenerateRoute: (settings) {
final uri = Uri.parse(settings.name ?? '');
if (uri.pathSegments.first == 'product') {
final productId = uri.pathSegments[1];
return MaterialPageRoute(
builder: (_) => ProductDetailPage(id: productId),
);
}
if (uri.pathSegments.first == 'order') {
final orderId = uri.pathSegments[1];
return MaterialPageRoute(
builder: (_) => OrderTrackingPage(id: orderId),
);
}
return MaterialPageRoute(builder: (_) => const HomePage());
},
)ਵਧੇਰੇ ਮਜ਼ਬੂਤ ਡੂੰਘੇ ਲਿੰਕਿੰਗ ਲਈ,go_routerਪੈਕੇਜ ਦੀ ਵਰਤੋਂ ਕਰੋ ਜੋ ਡੂੰਘੇ ਲਿੰਕ ਸਮਰਥਨ, ਰੀਡਾਇਰੈਕਟਸ, ਅਤੇ ਨੇਸਟਡ ਨੈਵੀਗੇਸ਼ਨ ਦੇ ਨਾਲ ਘੋਸ਼ਣਾਤਮਕ ਰੂਟਿੰਗ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ।
CI/CD ਕੋਡਮੈਜਿਕ ਅਤੇ ਫਾਸਟਲੇਨ ਦੇ ਨਾਲ
ਆਟੋਮੇਟਿਡ ਬਿਲਡ ਅਤੇ ਡਿਪਲਾਇਮੈਂਟ ਪਾਈਪਲਾਈਨਾਂ ਉਤਪਾਦਨ ਐਪਾਂ ਲਈ ਜ਼ਰੂਰੀ ਹਨ। ਕੋਡਮੈਜਿਕ ਇੱਕ Flutter-ਨੇਟਿਵ CI/CD ਸੇਵਾ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ, ਜਦੋਂ ਕਿ ਫਾਸਟਲੇਨ ਵਧੇਰੇ ਅਨੁਕੂਲਿਤ ਆਟੋਮੇਸ਼ਨ ਦੀ ਪੇਸ਼ਕਸ਼ ਕਰਦਾ ਹੈ।
ਕੋਡਮੈਜਿਕ ਕੌਂਫਿਗਰੇਸ਼ਨ
# codemagic.yaml
workflows:
production-release:
name: Production Release
max_build_duration: 60
environment:
flutter: stable
vars:
APP_STORE_CONNECT_KEY_ID: Encrypted(...)
GOOGLE_PLAY_SERVICE_ACCOUNT: Encrypted(...)
scripts:
- name: Install dependencies
script: flutter pub get
- name: Run tests
script: flutter test --coverage
- name: Build Android
script: flutter build appbundle --release
- name: Build iOS
script: |
flutter build ipa --release \
--export-options-plist=/path/to/ExportOptions.plist
artifacts:
- build/**/outputs/**/*.aab
- build/ios/ipa/*.ipa
publishing:
google_play:
credentials: $GOOGLE_PLAY_SERVICE_ACCOUNT
track: internal
app_store_connect:
api_key: $APP_STORE_CONNECT_KEY_IDਫਾਸਟਲੇਨ ਏਕੀਕਰਣ
ਫਾਸਟਲੇਨ ਬਿਲਡ ਅਤੇ ਸਬਮਿਸ਼ਨ ਪ੍ਰਕਿਰਿਆ ਉੱਤੇ ਦਾਣੇਦਾਰ ਨਿਯੰਤਰਣ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ। ਵੱਖ-ਵੱਖ ਰੀਲੀਜ਼ ਪੜਾਵਾਂ ਲਈ ਲੇਨਾਂ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰੋ:
# fastlane/Fastfile
platform :ios do
desc "Deploy to TestFlight"
lane :beta do
build_flutter_app(target: "lib/main.dart")
upload_to_testflight(
skip_waiting_for_build_processing: true
)
end
desc "Deploy to App Store"
lane :release do
build_flutter_app(target: "lib/main.dart")
upload_to_app_store(
submit_for_review: true,
automatic_release: false
)
end
endਪ੍ਰਦਰਸ਼ਨ ਪ੍ਰੋਫਾਈਲਿੰਗ
ਉਤਪਾਦਨ ਐਪਸ ਨਿਰੰਤਰ ਪ੍ਰਦਰਸ਼ਨ ਦੀ ਮੰਗ ਕਰਦੇ ਹਨ। Flutter DevTools ਵਿਆਪਕ ਪ੍ਰੋਫਾਈਲਿੰਗ ਸਮਰੱਥਾਵਾਂ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ।
- ਵਿਜੇਟ ਰੀਬਿਲਡ ਟ੍ਰੈਕਿੰਗ- ਵਿਜੇਟਸ ਦੀ ਪਛਾਣ ਕਰਨ ਲਈ ਪ੍ਰਦਰਸ਼ਨ ਓਵਰਲੇ ਅਤੇ DevTools ਦੀ ਵਰਤੋਂ ਕਰੋ ਜੋ ਬਹੁਤ ਜ਼ਿਆਦਾ ਦੁਬਾਰਾ ਬਣਦੇ ਹਨ। ਮੁੜ ਨਿਰਮਾਣ ਨੂੰ ਘੱਟ ਤੋਂ ਘੱਟ ਕਰਨ ਲਈ
constਕੰਸਟਰਕਟਰ ਅਤੇ ਚੋਣਵੇਂ ਰਾਜ ਪ੍ਰਬੰਧਨ ਨੂੰ ਲਾਗੂ ਕਰੋ। - ਫਰੇਮ ਰੈਂਡਰਿੰਗ- ਫਰੇਮ 16ms (60fps) ਜਾਂ 8ms (120fps) ਦੇ ਅੰਦਰ ਰੈਂਡਰ ਹੋਣ ਨੂੰ ਯਕੀਨੀ ਬਣਾਉਣ ਲਈ ਟਾਈਮਲਾਈਨ ਦ੍ਰਿਸ਼ ਦੀ ਨਿਗਰਾਨੀ ਕਰੋ। ਮਹਿੰਗੇ ਬਿਲਡ, ਲੇਆਉਟ ਅਤੇ ਪੇਂਟ ਪੜਾਵਾਂ ਦੀ ਭਾਲ ਕਰੋ।
- ਮੈਮੋਰੀ ਪ੍ਰੋਫਾਈਲਿੰਗ- ਲੀਕ ਦਾ ਪਤਾ ਲਗਾਉਣ ਲਈ ਮੈਮੋਰੀ ਵੰਡ ਨੂੰ ਟਰੈਕ ਕਰੋ। ਆਮ ਦੋਸ਼ੀਆਂ ਵਿੱਚ ਰੱਦ ਨਾ ਕੀਤੀਆਂ ਸਟ੍ਰੀਮ ਸਬਸਕ੍ਰਿਪਸ਼ਨਾਂ, ਅਣਡਿਪੋਜ਼ਡ ਕੰਟਰੋਲਰ, ਅਤੇ ਬੰਦ ਹੋਣ ਵਿੱਚ ਬਰਕਰਾਰ ਹਵਾਲੇ ਸ਼ਾਮਲ ਹਨ।
- ਸ਼ੁਰੂਆਤੀ ਪ੍ਰਦਰਸ਼ਨ-
WidgetsBinding.instance.addPostFrameCallbackਦੀ ਵਰਤੋਂ ਕਰਕੇ ਭਾਰੀ ਸ਼ੁਰੂਆਤ ਨੂੰ ਮੁਲਤਵੀ ਕਰੋ। ਉਹਨਾਂ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਲਈdeferred asਆਯਾਤ ਦੇ ਨਾਲ ਮੁਲਤਵੀ ਲੋਡਿੰਗ ਦੀ ਵਰਤੋਂ ਕਰੋ ਜਿਨ੍ਹਾਂ ਦੀ ਤੁਰੰਤ ਲੋੜ ਨਹੀਂ ਹੈ।
// Profile-mode build for accurate performance measurement
// flutter run --profile
// Add performance overlay in debug builds
MaterialApp(
showPerformanceOverlay: true,
// ...
)ਸਿੱਟਾ
ਉਤਪਾਦਨ ਲਈ ਤਿਆਰ Flutter ਐਪਲੀਕੇਸ਼ਨਾਂ ਲਈ ਵਿਜੇਟ ਕੈਟਾਲਾਗ ਨੂੰ ਜਾਣਨ ਤੋਂ ਇਲਾਵਾ ਹੋਰ ਵੀ ਬਹੁਤ ਕੁਝ ਦੀ ਲੋੜ ਹੈ। ਇਹ ਵਿਚਾਰਸ਼ੀਲ ਆਰਕੀਟੈਕਚਰ, ਮਜ਼ਬੂਤ ਰਾਜ ਪ੍ਰਬੰਧਨ, ਵਿਆਪਕ ਟੈਸਟਿੰਗ, ਅਤੇ ਸਵੈਚਲਿਤ ਤੈਨਾਤੀ ਪਾਈਪਲਾਈਨਾਂ ਦੀ ਮੰਗ ਕਰਦਾ ਹੈ। ਸਾਫ਼ ਆਰਕੀਟੈਕਚਰ ਨੂੰ ਅਪਣਾ ਕੇ, ਸਹੀ ਨਿਰਭਰਤਾ ਟੀਕੇ ਵਿੱਚ ਨਿਵੇਸ਼ ਕਰਕੇ, ਪੂਰੀ ਤਰ੍ਹਾਂ ਗਲਤੀ ਨਾਲ ਨਜਿੱਠਣ ਨੂੰ ਲਾਗੂ ਕਰਕੇ, ਅਤੇ CI/CD ਵਰਕਫਲੋਜ਼ ਨੂੰ ਸਥਾਪਿਤ ਕਰਕੇ, ਤੁਸੀਂ ਅਜਿਹੀਆਂ ਐਪਲੀਕੇਸ਼ਨਾਂ ਬਣਾਉਂਦੇ ਹੋ ਜੋ ਨਾ ਸਿਰਫ਼ ਕਾਰਜਸ਼ੀਲ ਹਨ ਪਰ ਲੰਬੇ ਸਮੇਂ ਲਈ ਰੱਖ-ਰਖਾਅਯੋਗ ਅਤੇ ਮਾਪਣਯੋਗ ਹਨ।
ਆਪਣੇ ਆਰਕੀਟੈਕਚਰ ਨੂੰ ਜਲਦੀ ਸਥਾਪਿਤ ਕਰਕੇ ਸ਼ੁਰੂ ਕਰੋ, ਪਹਿਲੇ ਦਿਨ ਤੋਂ ਟੈਸਟ ਲਿਖੋ, ਅਤੇ ਆਪਣੀ ਪਹਿਲੀ ਰਿਲੀਜ਼ ਤੋਂ ਪਹਿਲਾਂ ਆਪਣੀ ਡਿਪਲਾਇਮੈਂਟ ਪਾਈਪਲਾਈਨ ਨੂੰ ਸਵੈਚਲਿਤ ਕਰੋ। ਇਹ ਸ਼ੁਰੂਆਤੀ ਨਿਵੇਸ਼ ਸਮੇਂ ਦੇ ਨਾਲ ਸੰਯੁਕਤ ਹੋ ਜਾਂਦੇ ਹਨ, ਤੁਹਾਡੀ ਟੀਮ ਨੂੰ ਘੱਟ ਰੀਗਰੈਸ਼ਨਾਂ ਅਤੇ ਹਰ ਰੀਲੀਜ਼ ਵਿੱਚ ਵਧੇਰੇ ਵਿਸ਼ਵਾਸ ਨਾਲ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਨੂੰ ਤੇਜ਼ੀ ਨਾਲ ਭੇਜਣ ਦੇ ਯੋਗ ਬਣਾਉਂਦੇ ਹਨ।