Skip to content

Commit

Permalink
dynamic data via data.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmzdev committed Oct 5, 2024
1 parent 59ac27f commit 324a31d
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 213 deletions.
2 changes: 1 addition & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AppState extends State<App> {

// Renders a <div class="main"> html element with children.
yield div(classes: 'main', [
const Home(),
Home(),
]);
}

Expand Down
7 changes: 4 additions & 3 deletions data.json → lib/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"url": "https://mhmzdev.medium.com"
}
],
"aboutMe": {
"about": {
"heading": "I'm Muhammad Hamza, a Flutter Developer, Technical blog writer and UI/UX Designer.",
"description": "I'm a fresh graduate with Computer Science as Majors from COMSATS University Islamabad. I have been working with Flutter for the past 2 years and have developed multiple applications for both Android and iOS platforms. I have a keen interest in UI/UX designing and have been working on it for the past 3 years. I have also been writing technical blogs for the past 2 years and have been a part of multiple technical writing communities.",
"tech": [
"Flutter",
Expand All @@ -63,7 +64,7 @@
"height": 30
},
{
"image": "images/work/flutterisl.png",
"image": "images/work/flutterIsl.png",
"url": "https://meetup.com/flutter-islamabad",
"height": 60
},
Expand All @@ -76,7 +77,7 @@
},
"services": [
{
"icon": "images/services/mobile.png",
"icon": "images/services/app.png",
"title": "Mobile Development"
},
{
Expand Down
3 changes: 2 additions & 1 deletion lib/jaspr_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final defaultJasprOptions = JasprOptions(
prefix3.NavBar: ClientTarget<prefix3.NavBar>('components/nav_bar'),
prefix4.ProjectCard: ClientTarget<prefix4.ProjectCard>('components/project_card', params: _prefix4ProjectCard),
prefix5.ServiceCard: ClientTarget<prefix5.ServiceCard>('components/service_card', params: _prefix5ServiceCard),
prefix7.AboutMeSection: ClientTarget<prefix7.AboutMeSection>('sections/about_me'),
prefix7.AboutMeSection: ClientTarget<prefix7.AboutMeSection>('sections/about_me', params: _prefix7AboutMeSection),
},
styles: () => [
...prefix0.AppButton.styles,
Expand All @@ -67,3 +67,4 @@ Map<String, dynamic> _prefix1ContactCard(prefix1.ContactCard c) =>
Map<String, dynamic> _prefix4ProjectCard(prefix4.ProjectCard c) =>
{'title': c.title, 'description': c.description, 'icon': c.icon, 'banner': c.banner, 'url': c.url};
Map<String, dynamic> _prefix5ServiceCard(prefix5.ServiceCard c) => {'icon': c.icon, 'label': c.label};
Map<String, dynamic> _prefix7AboutMeSection(prefix7.AboutMeSection c) => {'about': c.about, 'basic': c.basic};
1 change: 1 addition & 0 deletions lib/models/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class About with _$About {
required String description,
required List<String> tech,
required List<Work> works,
required String heading,
}) = _About;

factory About.fromJson(Map<String, Object?> json) => _$AboutFromJson(json);
Expand Down
42 changes: 35 additions & 7 deletions lib/models/about.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mixin _$About {
String get description => throw _privateConstructorUsedError;
List<String> get tech => throw _privateConstructorUsedError;
List<Work> get works => throw _privateConstructorUsedError;
String get heading => throw _privateConstructorUsedError;

/// Serializes this About to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -38,7 +39,11 @@ abstract class $AboutCopyWith<$Res> {
factory $AboutCopyWith(About value, $Res Function(About) then) =
_$AboutCopyWithImpl<$Res, About>;
@useResult
$Res call({String description, List<String> tech, List<Work> works});
$Res call(
{String description,
List<String> tech,
List<Work> works,
String heading});
}

/// @nodoc
Expand All @@ -59,6 +64,7 @@ class _$AboutCopyWithImpl<$Res, $Val extends About>
Object? description = null,
Object? tech = null,
Object? works = null,
Object? heading = null,
}) {
return _then(_value.copyWith(
description: null == description
Expand All @@ -73,6 +79,10 @@ class _$AboutCopyWithImpl<$Res, $Val extends About>
? _value.works
: works // ignore: cast_nullable_to_non_nullable
as List<Work>,
heading: null == heading
? _value.heading
: heading // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}
Expand All @@ -84,7 +94,11 @@ abstract class _$$AboutImplCopyWith<$Res> implements $AboutCopyWith<$Res> {
__$$AboutImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String description, List<String> tech, List<Work> works});
$Res call(
{String description,
List<String> tech,
List<Work> works,
String heading});
}

/// @nodoc
Expand All @@ -103,6 +117,7 @@ class __$$AboutImplCopyWithImpl<$Res>
Object? description = null,
Object? tech = null,
Object? works = null,
Object? heading = null,
}) {
return _then(_$AboutImpl(
description: null == description
Expand All @@ -117,6 +132,10 @@ class __$$AboutImplCopyWithImpl<$Res>
? _value._works
: works // ignore: cast_nullable_to_non_nullable
as List<Work>,
heading: null == heading
? _value.heading
: heading // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
Expand All @@ -127,7 +146,8 @@ class _$AboutImpl implements _About {
const _$AboutImpl(
{required this.description,
required final List<String> tech,
required final List<Work> works})
required final List<Work> works,
required this.heading})
: _tech = tech,
_works = works;

Expand All @@ -152,9 +172,12 @@ class _$AboutImpl implements _About {
return EqualUnmodifiableListView(_works);
}

@override
final String heading;

@override
String toString() {
return 'About(description: $description, tech: $tech, works: $works)';
return 'About(description: $description, tech: $tech, works: $works, heading: $heading)';
}

@override
Expand All @@ -165,7 +188,8 @@ class _$AboutImpl implements _About {
(identical(other.description, description) ||
other.description == description) &&
const DeepCollectionEquality().equals(other._tech, _tech) &&
const DeepCollectionEquality().equals(other._works, _works));
const DeepCollectionEquality().equals(other._works, _works) &&
(identical(other.heading, heading) || other.heading == heading));
}

@JsonKey(includeFromJson: false, includeToJson: false)
Expand All @@ -174,7 +198,8 @@ class _$AboutImpl implements _About {
runtimeType,
description,
const DeepCollectionEquality().hash(_tech),
const DeepCollectionEquality().hash(_works));
const DeepCollectionEquality().hash(_works),
heading);

/// Create a copy of About
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -196,7 +221,8 @@ abstract class _About implements About {
const factory _About(
{required final String description,
required final List<String> tech,
required final List<Work> works}) = _$AboutImpl;
required final List<Work> works,
required final String heading}) = _$AboutImpl;

factory _About.fromJson(Map<String, dynamic> json) = _$AboutImpl.fromJson;

Expand All @@ -206,6 +232,8 @@ abstract class _About implements About {
List<String> get tech;
@override
List<Work> get works;
@override
String get heading;

/// Create a copy of About
/// with the given fields replaced by the non-null parameter values.
Expand Down
2 changes: 2 additions & 0 deletions lib/models/about.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 34 additions & 9 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
import 'dart:convert';
import 'dart:io';
import 'package:devfolio/components/footer.dart';
import 'package:devfolio/components/nav_bar.dart';
import 'package:devfolio/models/data.dart';
import 'package:devfolio/sections/about_me.dart';
import 'package:devfolio/sections/basic_info.dart';
import 'package:devfolio/sections/contact.dart';
import 'package:devfolio/sections/projects.dart';
import 'package:devfolio/sections/services.dart';
import 'package:jaspr/jaspr.dart';
import 'package:jaspr/server.dart';

class Home extends StatelessComponent {
const Home({super.key});
class Home extends AsyncStatelessComponent {
Future<Data> fetchData() async {
final String responseProjects =
File('lib/data/data.json').readAsStringSync();
final Map<String, dynamic> raw =
jsonDecode(responseProjects) as Map<String, dynamic>;

final data = Data.fromJson(raw);
return data;
}

@override
Iterable<Component> build(BuildContext context) sync* {
Stream<Component> build(BuildContext context) async* {
final data = await fetchData();

yield div(classes: 'home-body', [
NavBar(),
BasicInfoSection(),
AboutMeSection(),
ServicesSection(),
ProjectsSections(),
ContactSection(),
BasicInfoSection(
basic: data.basic,
socials: data.socials,
),
AboutMeSection(
about: data.about,
basic: data.basic,
),
ServicesSection(
services: data.services,
),
ProjectsSections(
projects: data.projects,
),
ContactSection(
contacts: data.contact,
),
Footer(),
]);
}
Expand Down
Loading

0 comments on commit 324a31d

Please sign in to comment.