Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: Extract AppVersionText into a separate widget + Add a new widget = ChipText #251

Merged
merged 6 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/cosmos_ui_components/lib/components/app_version_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:cosmos_utils/app_info_provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class AppVersionText extends StatelessWidget {
const AppVersionText({
required this.appInfoProvider,
this.style,
Key? key,
}) : super(key: key);
final AppInfoProvider appInfoProvider;
final TextStyle? style;

@override
Widget build(BuildContext context) => FutureBuilder<String>(
future: appInfoProvider.getAppVersion(),
builder: (context, snapshot) => Text(
snapshot.data ?? '',
style: style,
),
);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<AppInfoProvider>('appInfoProvider', appInfoProvider))
..add(DiagnosticsProperty<TextStyle?>('style', style));
}
}
40 changes: 40 additions & 0 deletions packages/cosmos_ui_components/lib/components/chip_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:cosmos_ui_components/cosmos_ui_components.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class ChipText extends StatelessWidget {
const ChipText({
required this.title,
this.style,
this.backgroundColor,
Key? key,
}) : super(key: key);
final String title;
final TextStyle? style;
final Color? backgroundColor;

@override
Widget build(BuildContext context) {
final theme = CosmosTheme.of(context);
return Container(
padding: EdgeInsets.all(theme.spacingM),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: backgroundColor ?? theme.colors.chipBackground,
),
child: Text(
title,
style: style,
),
);
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(StringProperty('title', title))
..add(DiagnosticsProperty<TextStyle?>('style', style))
..add(ColorProperty('backgroundColor', backgroundColor));
}
}
2 changes: 2 additions & 0 deletions packages/cosmos_ui_components/lib/cosmos_ui_components.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
library cosmos_ui_components;

export 'components/app_version_text.dart';
export 'components/chip_text.dart';
export 'components/content_loading_indicator.dart';
export 'components/content_state_switcher.dart';
export 'components/cosmos_app_bar.dart';
Expand Down