75 lines
2.6 KiB
Dart
75 lines
2.6 KiB
Dart
import 'package:didvan/config/design_config.dart';
|
|
import 'package:didvan/config/theme_data.dart';
|
|
import 'package:didvan/services/app_initalizer.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/views/home/home_state.dart';
|
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
|
|
|
class MainCategories extends StatelessWidget {
|
|
const MainCategories({super.key});
|
|
|
|
void _onTap(String link, BuildContext context) {
|
|
if (link.startsWith('http')) {
|
|
AppInitializer.openWebLink(
|
|
context,
|
|
'$link?accessToken=${RequestService.token}',
|
|
mode: LaunchMode.inAppWebView,
|
|
);
|
|
print("your goddamn token is :${RequestService.token}");
|
|
} else if (link.startsWith('tab-')) {
|
|
final state = context.read<HomeState>();
|
|
int index = int.parse(link.replaceAll('tab-', ''));
|
|
state.currentPageIndex = index;
|
|
state.tabController.animateTo(index);
|
|
} else {
|
|
Navigator.of(context).pushNamed(link);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = context.read<HomeState>();
|
|
return Wrap(
|
|
alignment: WrapAlignment.start,
|
|
children: state.menuItems
|
|
.map(
|
|
(e) => GestureDetector(
|
|
onTap: () => _onTap(e.link, context),
|
|
child: SizedBox(
|
|
width: (MediaQuery.of(context).size.width) / 4,
|
|
// (MediaQuery.of(context).size.width - 40) / 3,
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
width: 56,
|
|
height: 56,
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
borderRadius: DesignConfig.lowBorderRadius,
|
|
boxShadow: DesignConfig.defaultShadow,
|
|
),
|
|
child: SvgPicture.asset(e.asset),
|
|
),
|
|
const SizedBox(height: 4),
|
|
DidvanText(
|
|
e.label,
|
|
color: Theme.of(context).colorScheme.title,
|
|
style: Theme.of(context).textTheme.labelSmall,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
const SizedBox(height: 12),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.toList(),
|
|
);
|
|
}
|
|
}
|