Skip to content

Commit e4e08af

Browse files
committed
Sample Data Creation
1 parent 7394e9e commit e4e08af

4 files changed

Lines changed: 221 additions & 30 deletions

File tree

lib/model/model_package.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'dart:convert';
2+
3+
class PackageModel {
4+
PackageModel({
5+
this.name,
6+
this.description,
7+
this.publisher,
8+
});
9+
10+
final String name;
11+
final String description;
12+
final String publisher;
13+
14+
PackageModel copyWith({
15+
String title,
16+
String description,
17+
String publisher,
18+
}) =>
19+
PackageModel(
20+
name: title ?? this.name,
21+
description: description ?? this.description,
22+
publisher: publisher ?? this.publisher,
23+
);
24+
25+
factory PackageModel.fromJson(String str) =>
26+
PackageModel.fromMap(json.decode(str));
27+
28+
String toJson() => json.encode(toMap());
29+
30+
factory PackageModel.fromMap(Map<String, dynamic> json) => PackageModel(
31+
name: json["name"] == null ? null : json["name"],
32+
description: json["description"] == null ? null : json["description"],
33+
publisher: json["publisher"] == null ? null : json["publisher"],
34+
);
35+
36+
Map<String, dynamic> toMap() => {
37+
"name": name == null ? null : name,
38+
"description": description == null ? null : description,
39+
"publisher": publisher == null ? null : publisher,
40+
};
41+
42+
@override
43+
String toString() =>
44+
"PackageModel(name: '$name', description: '$description', publisher: '$publisher')";
45+
}

lib/packages_data.dart

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import 'model/model_package.dart';
2+
3+
List<PackageModel> favoritePackages = [
4+
PackageModel(
5+
name: 'responsive_framework',
6+
description:
7+
'Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple.',
8+
publisher: 'codelessly.com'),
9+
PackageModel(
10+
name: 'loading_gifs',
11+
description:
12+
'Loading indicator GIFs. Material and Cupertino (Android and iOS) loading indicators in assorted sizes. Use as placeholders for loading remote image assets.',
13+
publisher: 'codelessly.com'),
14+
PackageModel(
15+
name: 'audioplayers',
16+
description:
17+
'A flutter plugin to play multiple audio files simultaneously',
18+
publisher: 'fireslime.xyz'),
19+
PackageModel(
20+
name: 'flutter_html',
21+
description:
22+
'A Flutter widget rendering static HTML and CSS as Flutter widgets.',
23+
publisher: 'sub6resources.com'),
24+
];
25+
26+
List<PackageModel> popularPackages = [
27+
PackageModel(
28+
name: 'cloud_firestore',
29+
description:
30+
'Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database with live synchronization and offline support on Android and iOS.',
31+
publisher: 'firebase.google.com'),
32+
PackageModel(
33+
name: 'auto_size_text',
34+
description:
35+
'Flutter widget that automatically resizes text to fit perfectly within its bounds.',
36+
publisher: ''),
37+
PackageModel(
38+
name: 'flushbar',
39+
description:
40+
'A flexible widget for user notification. Customize your text, button, duration, animations and much more. For Android devs, it is made to replace Snackbars and Toasts.',
41+
publisher: ''),
42+
PackageModel(
43+
name: 'shimmer',
44+
description:
45+
'A package provides an easy way to add shimmer effect in Flutter project',
46+
publisher: ''),
47+
PackageModel(
48+
name: 'smooth_page_indicator',
49+
description:
50+
'Customizable animated page indicator with a set of built-in effects.',
51+
publisher: ''),
52+
PackageModel(
53+
name: 'confetti',
54+
description:
55+
'Blast colorful confetti all over the screen. Celebrate in app achievements with style. Control the velocity, angle, gravity and amount of confetti.',
56+
publisher: ''),
57+
];
58+
59+
List<PackageModel> topFlutterPackages = [
60+
PackageModel(
61+
name: 'flutter_linkify',
62+
description:
63+
'Turns text URLs and emails into clickable inline links in text for Flutter.',
64+
publisher: 'cretezy.com'),
65+
PackageModel(
66+
name: 'like_button',
67+
description:
68+
'Like Button is a flutter library that allows you to create a button with animation effects similar to Twitter&#x27;s heart when you like something.',
69+
publisher: 'fluttercandies.com'),
70+
PackageModel(
71+
name: 'convex_bottom_bar',
72+
description:
73+
'A Flutter package which implements a ConvexAppBar to show a convex tab in the bottom bar. Theming supported.',
74+
publisher: 'hacktons.cn'),
75+
PackageModel(
76+
name: 'sleek_circular_slider',
77+
description:
78+
'A highly customizable circular slider/progress bar & spinner for Flutter.',
79+
publisher: ''),
80+
PackageModel(
81+
name: 'scroll_to_index',
82+
description: 'scroll to the index of any scrollable widget in Flutter',
83+
publisher: ''),
84+
PackageModel(
85+
name: 'flutter_animator',
86+
description:
87+
'Create animations with less code in a chaining manner. This package allows you to combine and chain multiple animations based on percentages of the duration.',
88+
publisher: ''),
89+
];
90+
91+
List<PackageModel> topDartPackages = [
92+
PackageModel(
93+
name: 'bloc',
94+
description:
95+
'A predictable state management library that helps implement the BLoC (Business Logic Component) design pattern.',
96+
publisher: 'bloclibrary.dev'),
97+
PackageModel(
98+
name: 'flutter_cache_manager',
99+
description:
100+
'Generic cache manager for flutter. Saves web files on the storages of the device and saves the cache info using sqflite.',
101+
publisher: 'baseflow.com'),
102+
PackageModel(
103+
name: 'petitparser',
104+
description:
105+
'A dynamic parser framework to build efficient grammars and parsers quickly.',
106+
publisher: 'lukas-renggli.ch'),
107+
PackageModel(
108+
name: 'universal_html',
109+
description:
110+
'A \'dart:html\' that works in all platforms, including Flutter and server-side. Eases cross-platform development and other HTML / XML processing.',
111+
publisher: 'dint.dev'),
112+
PackageModel(
113+
name: 'dio',
114+
description:
115+
'A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.',
116+
publisher: 'flutterchina.club'),
117+
PackageModel(
118+
name: 'mobx_codegen',
119+
description:
120+
'Code generator for MobX that adds support for annotating your code with @observable, @computed, @action and also creating Store classes.',
121+
publisher: 'dart.pixelingene.com'),
122+
];

lib/ui/blocks.dart

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import 'package:flutter/gestures.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter/rendering.dart';
44
import 'package:pub_dev/components/components.dart';
5+
import 'package:pub_dev/model/model_package.dart';
6+
import 'package:pub_dev/packages_data.dart';
57
import 'package:pub_dev/utils/utils.dart';
68
import 'package:responsive_framework/responsive_framework.dart';
79

@@ -187,12 +189,12 @@ class FlutterFavorites extends StatelessWidget {
187189
crossAxisSpacing: 16,
188190
childAspectRatio: 1.37),
189191
maxRowCount: 1,
190-
itemCount: 4,
192+
itemCount: favoritePackages.length,
191193
shrinkWrap: true,
192194
padding: EdgeInsets.fromLTRB(4, 8, 0, 8),
193195
alignment: Alignment.center,
194196
itemBuilder: (context, index) {
195-
return PackageCard();
197+
return PackageCard(package: favoritePackages[index]);
196198
},
197199
),
198200
Align(
@@ -221,6 +223,7 @@ class MostPopular extends StatelessWidget {
221223
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 20),
222224
child: Row(
223225
mainAxisSize: MainAxisSize.min,
226+
mainAxisAlignment: MainAxisAlignment.center,
224227
children: [
225228
Flexible(
226229
child: ConstrainedBox(
@@ -249,12 +252,12 @@ class MostPopular extends StatelessWidget {
249252
crossAxisSpacing: 16,
250253
childAspectRatio: 1.37),
251254
maxRowCount: 2,
252-
itemCount: 6,
255+
itemCount: popularPackages.length,
253256
shrinkWrap: true,
254257
padding: EdgeInsets.fromLTRB(4, 8, 0, 16),
255258
alignment: Alignment.center,
256259
itemBuilder: (context, index) {
257-
return PackageCard();
260+
return PackageCard(package: popularPackages[index]);
258261
},
259262
),
260263
),
@@ -289,6 +292,7 @@ class TopFlutter extends StatelessWidget {
289292
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 20),
290293
child: Row(
291294
mainAxisSize: MainAxisSize.min,
295+
mainAxisAlignment: MainAxisAlignment.center,
292296
children: [
293297
Column(
294298
mainAxisSize: MainAxisSize.min,
@@ -310,12 +314,12 @@ class TopFlutter extends StatelessWidget {
310314
crossAxisSpacing: 16,
311315
childAspectRatio: 1.37),
312316
maxRowCount: 2,
313-
itemCount: 6,
317+
itemCount: topFlutterPackages.length,
314318
shrinkWrap: true,
315319
padding: EdgeInsets.fromLTRB(4, 8, 0, 16),
316320
alignment: Alignment.center,
317321
itemBuilder: (context, index) {
318-
return PackageCard();
322+
return PackageCard(package: topFlutterPackages[index]);
319323
},
320324
),
321325
),
@@ -359,6 +363,7 @@ class TopDart extends StatelessWidget {
359363
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 20),
360364
child: Row(
361365
mainAxisSize: MainAxisSize.min,
366+
mainAxisAlignment: MainAxisAlignment.center,
362367
children: [
363368
Flexible(
364369
child: Container(
@@ -376,8 +381,8 @@ class TopDart extends StatelessWidget {
376381
mainAxisAlignment: MainAxisAlignment.center,
377382
children: [
378383
Padding(padding: EdgeInsets.only(bottom: 24)),
379-
Text('Top Flutter packages', style: titleTextStyle),
380-
Text('Top packages that extend Flutter with new features',
384+
Text('Top Dart packages', style: titleTextStyle),
385+
Text('Top packages for any Dart-based app or program',
381386
style: TextStyle(
382387
color: textPrimaryColor, fontSize: 18, height: 1.6)),
383388
Padding(padding: EdgeInsets.only(bottom: 10)),
@@ -390,12 +395,12 @@ class TopDart extends StatelessWidget {
390395
crossAxisSpacing: 16,
391396
childAspectRatio: 1.37),
392397
maxRowCount: 2,
393-
itemCount: 6,
398+
itemCount: topDartPackages.length,
394399
shrinkWrap: true,
395400
padding: EdgeInsets.fromLTRB(4, 8, 0, 16),
396401
alignment: Alignment.center,
397402
itemBuilder: (context, index) {
398-
return PackageCard();
403+
return PackageCard(package: topDartPackages[index]);
399404
},
400405
),
401406
),
@@ -423,6 +428,10 @@ class TopDart extends StatelessWidget {
423428
}
424429

425430
class PackageCard extends StatelessWidget {
431+
final PackageModel package;
432+
433+
const PackageCard({Key key, @required this.package}) : super(key: key);
434+
426435
@override
427436
Widget build(BuildContext context) {
428437
return Container(
@@ -438,27 +447,34 @@ class PackageCard extends StatelessWidget {
438447
child: Column(
439448
crossAxisAlignment: CrossAxisAlignment.start,
440449
children: [
441-
Text('responsive_framework', style: linkTitleTextStyle),
442-
Text(
443-
'Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple.',
444-
style:
445-
TextStyle(color: textPrimaryColor, fontSize: 14, height: 1.6),
446-
maxLines: 3,
447-
overflow: TextOverflow.clip),
448-
Padding(padding: EdgeInsets.only(bottom: 20)),
449-
Row(
450-
crossAxisAlignment: CrossAxisAlignment.center,
451-
children: [
452-
Image.asset('assets/images/icon_verified_publisher.png',
453-
width: 14, height: 16),
454-
Padding(padding: EdgeInsets.only(right: 4)),
455-
GestureDetector(
456-
onTap: () => openUrl('https://codelessly.com'),
457-
child: Text('codelessly.com',
458-
style: TextStyle(color: linkColor, fontSize: 12)),
459-
),
460-
],
450+
GestureDetector(
451+
onTap: () => openUrl(buildPackageUrlFromName(package.name)),
452+
child: Text(package.name,
453+
style: linkTitleTextStyle, overflow: TextOverflow.ellipsis)),
454+
Expanded(
455+
child: Text(package.description,
456+
style: TextStyle(
457+
color: textPrimaryColor, fontSize: 14, height: 1.6),
458+
maxLines: 3,
459+
overflow: TextOverflow.clip),
461460
),
461+
Padding(padding: EdgeInsets.only(bottom: 16)),
462+
if (package.publisher.isNotEmpty)
463+
Row(
464+
crossAxisAlignment: CrossAxisAlignment.center,
465+
children: [
466+
Image.asset('assets/images/icon_verified_publisher.png',
467+
width: 14, height: 16),
468+
Padding(padding: EdgeInsets.only(right: 4)),
469+
GestureDetector(
470+
onTap: () =>
471+
openUrl(buildPublisherUrlFromName(package.publisher)),
472+
child: Text(package.publisher,
473+
style: TextStyle(color: linkColor, fontSize: 12)),
474+
),
475+
],
476+
),
477+
Padding(padding: EdgeInsets.only(bottom: 8)),
462478
],
463479
),
464480
);

lib/utils/utils.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ Future<bool> openUrl(String url, {bool newWindow = false}) async {
1010
return false;
1111
}
1212
}
13+
14+
String buildPackageUrlFromName(String name) {
15+
return 'https://pub.dev/packages/$name';
16+
}
17+
18+
String buildPublisherUrlFromName(String name) {
19+
return 'https://pub.dev/publishers/$name/packages';
20+
}

0 commit comments

Comments
 (0)