Skip to content

Commit 642f7f2

Browse files
authored
refactor: Extract AppVersionText into a separate widget + Add a new widget = ChipText (#251)
1 parent 018b231 commit 642f7f2

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:cosmos_utils/app_info_provider.dart';
2+
import 'package:flutter/foundation.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class AppVersionText extends StatelessWidget {
6+
const AppVersionText({
7+
required this.appInfoProvider,
8+
this.style,
9+
Key? key,
10+
}) : super(key: key);
11+
final AppInfoProvider appInfoProvider;
12+
final TextStyle? style;
13+
14+
@override
15+
Widget build(BuildContext context) => FutureBuilder<String>(
16+
future: appInfoProvider.getAppVersion(),
17+
builder: (context, snapshot) => Text(
18+
snapshot.data ?? '',
19+
style: style,
20+
),
21+
);
22+
23+
@override
24+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
25+
super.debugFillProperties(properties);
26+
properties
27+
..add(DiagnosticsProperty<AppInfoProvider>('appInfoProvider', appInfoProvider))
28+
..add(DiagnosticsProperty<TextStyle?>('style', style));
29+
}
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:cosmos_ui_components/cosmos_ui_components.dart';
2+
import 'package:flutter/foundation.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class ChipText extends StatelessWidget {
6+
const ChipText({
7+
required this.title,
8+
this.style,
9+
this.backgroundColor,
10+
Key? key,
11+
}) : super(key: key);
12+
final String title;
13+
final TextStyle? style;
14+
final Color? backgroundColor;
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
final theme = CosmosTheme.of(context);
19+
return Container(
20+
padding: EdgeInsets.all(theme.spacingM),
21+
decoration: BoxDecoration(
22+
borderRadius: BorderRadius.circular(10),
23+
color: backgroundColor ?? theme.colors.chipBackground,
24+
),
25+
child: Text(
26+
title,
27+
style: style,
28+
),
29+
);
30+
}
31+
32+
@override
33+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
34+
super.debugFillProperties(properties);
35+
properties
36+
..add(StringProperty('title', title))
37+
..add(DiagnosticsProperty<TextStyle?>('style', style))
38+
..add(ColorProperty('backgroundColor', backgroundColor));
39+
}
40+
}

packages/cosmos_ui_components/lib/cosmos_ui_components.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
library cosmos_ui_components;
22

3+
export 'components/app_version_text.dart';
4+
export 'components/chip_text.dart';
35
export 'components/content_loading_indicator.dart';
46
export 'components/content_state_switcher.dart';
57
export 'components/cosmos_app_bar.dart';

0 commit comments

Comments
 (0)