birzha_mobile/lib/components/baseWidget.dart

203 lines
6.7 KiB
Dart

import 'package:birzha/models/settings/settingsModel.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:birzha/components/icon.dart';
import 'package:birzha/components/tabview.dart';
import 'package:birzha/constants.dart';
import 'package:birzha/new/themes/colors.dart';
import 'package:birzha/screens/settings/contact.dart';
import '../core/adaptix/adaptix.dart';
import '../new/screens/news/screen.dart';
import '../screens/settings/settingsScreen.dart';
class BaseWidget extends StatelessWidget {
const BaseWidget({
Key? key,
this.bottom,
required this.appBar,
required this.body,
this.color,
}) : super(key: key);
final BaseAppBar appBar;
final Widget body;
final Widget? bottom;
final Color? color;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar,
body: body,
backgroundColor: color ?? Theme.of(context).scaffoldBackgroundColor,
bottomNavigationBar: bottom,
);
}
}
class BaseAppBar extends StatelessWidget implements PreferredSizeWidget {
BaseAppBar({
Key? key,
this.customChild,
this.after = const [],
this.title,
required this.goBack,
this.includeBack = true,
this.color = ThemeColor.mainColor,
}) : super(key: key);
final Widget? customChild;
final List<Widget> after;
final String? title;
final void Function() goBack;
final Color? color;
final bool includeBack;
factory BaseAppBar.home(BuildContext context, VoidCallback goBack) {
debugPrint('BaseAppBar.home');
List<MyNavigator> navigators = [
new MyNavigator(id: 1, name: "searchShort".translation, path: "search"),
new MyNavigator(id: 2, name: "settings".translation, path: "settings"),
new MyNavigator(id: 3, name: "contact".translation, path: "contact"),
];
return BaseAppBar(
goBack: goBack,
color: Theme.of(context).brightness == Brightness.light ? Theme.of(context).accentColor : Theme.of(context).appBarTheme.backgroundColor,
customChild: Padding(
padding: EdgeInsets.symmetric(
horizontal: AppConstants.horizontalPadding(context),
),
child: Row(
children: [
AppIconButton(
size: AppConstants.appBarIconSize,
onTap: () {
debugPrint('asd');
Navigator.of(context).push(MaterialPageRoute(builder: (_) => NewsScreen()));
},
icon: Icon(
Icons.newspaper_rounded,
color: ThemeColor.white,
),
),
Spacer(),
SvgPicture.asset(
'assets/images/appBarIcon.svg',
height: AppConstants.clearAppBarHeight * 0.75,
width: AppConstants.clearAppBarHeight * 0.88,
),
Container(
width: MediaQuery.of(context).size.width * 0.39,
child: DropdownButtonHideUnderline(
child: DropdownButton<MyNavigator>(
isExpanded: true,
borderRadius: BorderRadius.circular(16),
icon: Icon(
Icons.more_vert_rounded,
color: ThemeColor.white,
size: 22.adaptedPx(),
),
items: navigators.map(
(MyNavigator value) {
return DropdownMenuItem<MyNavigator>(
value: value,
child: Text(
value.name,
overflow: TextOverflow.ellipsis,
// style: AppTheme.selectedTxtStyle,
),
);
},
).toList(),
onChanged: (newValue) {
if (newValue!.path == 'search') {
Tabnavigator.maybeOf(context)?.changePage(1);
} else if (newValue.path == 'settings') {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (_) => SettingsScreen()),
);
} else if (newValue.path == 'contact') {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(builder: (_) => ContactScreen()),
);
}
},
),
),
),
],
),
),
);
}
@override
Size get preferredSize => Size.fromHeight(AppConstants.appBarHeight);
@override
Widget build(BuildContext context) {
return Container(
height: preferredSize.height,
padding: EdgeInsets.only(top: Adaptix.systemPadding.top),
color: color ?? Theme.of(context).appBarTheme.backgroundColor,
alignment: Alignment.centerLeft,
child: Material(
color: Colors.transparent,
child: Center(
child: customChild ??
Padding(
padding: EdgeInsets.symmetric(horizontal: AppConstants.horizontalPadding(context)),
child: Row(
children: [
if (includeBack)
AppIconButton(
icon: Icon(
CupertinoIcons.back,
color: ThemeColor.white, //Theme.of(context).appBarTheme.iconTheme?.color,
),
onTap: goBack,
size: AppConstants.appBarIconSize),
SizedBox(
width: 10.adaptedPx(),
),
Expanded(
child: Text(
title ?? "",
style: AppBarTheme.of(context).titleTextStyle?.copyWith(
fontWeight: FontWeight.w500,
color: ThemeColor.white, //Theme.of(context).accentTextTheme.headline2?.color,
),
),
),
SizedBox(
width: 10.adaptedPx(),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
for (var option in after) ...[SizedBox(width: 1.5.orientationWidth), option]
],
)
],
),
),
),
),
);
}
}
class MyNavigator {
int id;
String name;
String path;
MyNavigator({
required this.id,
required this.name,
required this.path,
});
}