-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathnews_service.dart
More file actions
30 lines (26 loc) · 953 Bytes
/
news_service.dart
File metadata and controls
30 lines (26 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'package:flutter_lorem/flutter_lorem.dart';
import 'package:flutter_testing_tutorial/article.dart';
/// A News service simulating communication with a server.
class NewsService {
/// In-memory list of articles that simulates a remote database.
/// Generates 10 articles with random lorem ipsum text for both
/// title and content.
final _articles = List.generate(
10,
(_) => Article(
title: lorem(paragraphs: 1, words: 3), // Generate a 3-word title
content: lorem(
paragraphs: 7, words: 500), // Generate content with 10 paragraphs
),
);
/// Fetches all articles from the simulated database.
///
/// Adds an artificial delay of 1 second to simulate network latency.
///
/// Returns:
/// Future<List<Article>>: A list of Article objects after the delay.
Future<List<Article>> getArticles() async {
await Future.delayed(const Duration(seconds: 1));
return _articles;
}
}