Skip to content

Commit

Permalink
fix: [NO-TASK] Get MDS version dynamically (#7)
Browse files Browse the repository at this point in the history
* [NO-TASK] Get MDS version dynamically

* [NO-TASK] Restore deleted changes
  • Loading branch information
Kypsis committed Feb 7, 2023
1 parent c753098 commit 568092c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
29 changes: 22 additions & 7 deletions example/lib/src/storybook/common/widgets/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ import 'package:flutter/material.dart';

import 'package:moon_design/moon_design.dart';

class MoonVersionWidget extends StatelessWidget {
final String version;
class MoonVersionWidget extends StatefulWidget {
const MoonVersionWidget({super.key});

const MoonVersionWidget({
super.key,
required this.version,
});
@override
State<MoonVersionWidget> createState() => _MoonVersionWidgetState();
}

class _MoonVersionWidgetState extends State<MoonVersionWidget> {
String? _version = "";

@override
Future<void> didChangeDependencies() async {
super.didChangeDependencies();

final fileContent = await DefaultAssetBundle.of(context).loadString("../pubspec.lock");
final entry = fileContent.split("moon_design:")[1].split("version:")[1];
final version = RegExp('"(.*?)"').firstMatch(entry)?.group(0)?.replaceAll('"', "");

setState(() {
_version = version;
});
}

@override
Widget build(BuildContext context) {
Expand All @@ -26,7 +41,7 @@ class MoonVersionWidget extends StatelessWidget {
style: MoonTypography.textStyles.text.text16,
),
const SizedBox(width: 6.0),
Text("v$version", style: MoonTypography.textStyles.heading.text16),
Text("v$_version", style: MoonTypography.textStyles.heading.text16),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/storybook/storybook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class StorybookPage extends StatelessWidget {
),
const Align(
alignment: Alignment.bottomCenter,
child: MoonVersionWidget(version: "0.1.0"),
child: MoonVersionWidget(),
),
],
);
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.1.0"
nested:
dependency: transitive
description:
Expand Down

0 comments on commit 568092c

Please sign in to comment.