Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sunarya-thito committed Feb 24, 2025
1 parent 26e5b9c commit fb3baae
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
16 changes: 16 additions & 0 deletions docs/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import 'package:docs/pages/docs/web_preloader_page.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart';
import 'package:shadcn_flutter/shadcn_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand All @@ -102,17 +103,32 @@ import 'pages/docs/components/number_input_example.dart';
const kEnablePersistentPath = false;

Map<String, Object?>? _docs;
String? _packageLatestVersion;

String? get packageLatestVersion => _packageLatestVersion;

String get flavor {
String? flavor = _docs?['flavor'] as String?;
assert(flavor != null, 'Flavor not found in docs.json');
return flavor!;
}

String getReleaseTagName() {
var latestVersion = packageLatestVersion;
return latestVersion == null ? 'Release' : 'Release ($latestVersion)';
}

void main() async {
WidgetsFlutterBinding.ensureInitialized();
_docs = jsonDecode(await rootBundle.loadString('docs.json'));
print('Running app with flavor: $flavor');
Uri checkVersionUri =
Uri.parse('https://pub.dev/packages/shadcn_flutter.json');
var response = await get(checkVersionUri);
if (response.statusCode == 200) {
var packageInfo = jsonDecode(response.body) as Map<String, dynamic>;
_packageLatestVersion = packageInfo['versions'][0];
}
GoRouter.optionURLReflectsImperativeAPIs = true;
final prefs = await SharedPreferences.getInstance();
var colorScheme = prefs.getString('colorScheme');
Expand Down
62 changes: 44 additions & 18 deletions docs/lib/pages/docs_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,29 +455,55 @@ class DocsPageState extends State<DocsPage> {
color = Colors.orange;
break;
case 'release':
text = 'Release';
text = getReleaseTagName();
color = Colors.green;
break;
}
return PrimaryBadge(
style: const ButtonStyle.primary(
density: ButtonDensity.dense,
size: ButtonSize.small,
).copyWith(
decoration: (context, states, value) {
return (value as BoxDecoration).copyWith(
color: color,
);
},
textStyle: (context, states, value) {
return value.copyWith(
color: Colors.white,
fontWeight: FontWeight.w500,
return Builder(builder: (context) {
return PrimaryBadge(
onPressed: () {
showDropdown(
context: context,
offset: Offset(0, 8) * Theme.of(context).scaling,
builder: (context) {
return DropdownMenu(
children: [
MenuButton(
child: Text(getReleaseTagName()),
onPressed: (context) {
launchUrlString('https://sunarya-thito.github.io/shadcn_flutter/');
},
),
MenuButton(
child: Text('Experimental'),
onPressed: (context) {
launchUrlString('https://sunarya-thito.github.io/shadcn_flutter/experimental/')
},
),
],
);
},
);
},
),
child: Text(text),
);
style: const ButtonStyle.primary(
density: ButtonDensity.dense,
size: ButtonSize.small,
).copyWith(
decoration: (context, states, value) {
return (value as BoxDecoration).copyWith(
color: color,
);
},
textStyle: (context, states, value) {
return value.copyWith(
color: Colors.white,
fontWeight: FontWeight.w500,
);
},
),
child: Text(text),
);
});
}

@override
Expand Down

0 comments on commit fb3baae

Please sign in to comment.