forked from TheAlphamerc/flutter_twitter_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomAppBar.dart
147 lines (139 loc) · 4.63 KB
/
customAppBar.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import 'package:flutter/material.dart';
import 'package:flutter_twitter_clone/state/authState.dart';
import 'package:flutter_twitter_clone/ui/page/profile/widgets/circular_image.dart';
import 'package:flutter_twitter_clone/ui/theme/theme.dart';
import 'package:provider/provider.dart';
import 'customWidgets.dart';
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
const CustomAppBar(
{Key? key,
this.title,
this.scaffoldKey,
this.icon,
this.onActionPressed,
this.textController,
this.isBackButton = false,
this.isCrossButton = false,
this.submitButtonText,
this.isSubmitDisable = true,
this.isBottomLine = true,
this.onSearchChanged})
: super(key: key);
final Size appBarHeight = const Size.fromHeight(56.0);
final IconData? icon;
final bool isBackButton;
final bool isBottomLine;
final bool isCrossButton;
final bool isSubmitDisable;
final Function? onActionPressed;
final GlobalKey<ScaffoldState>? scaffoldKey;
final String? submitButtonText;
final TextEditingController? textController;
final Widget? title;
final ValueChanged<String>? onSearchChanged;
@override
Size get preferredSize => appBarHeight;
Widget _searchField() {
return Container(
height: 50,
padding: const EdgeInsets.symmetric(vertical: 5),
child: TextField(
onChanged: onSearchChanged,
controller: textController,
decoration: const InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(width: 0, style: BorderStyle.none),
borderRadius: BorderRadius.all(
Radius.circular(25.0),
),
),
hintText: 'Search..',
fillColor: AppColor.extraLightGrey,
filled: true,
focusColor: Colors.white,
contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
),
));
}
List<Widget> _getActionButtons(BuildContext context) {
return <Widget>[
submitButtonText != null
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 12),
child: Container(
alignment: Alignment.center,
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 0),
decoration: BoxDecoration(
color: !isSubmitDisable
? Theme.of(context).primaryColor
: Theme.of(context).primaryColor.withAlpha(150),
borderRadius: BorderRadius.circular(20),
),
child: Text(
submitButtonText!,
style:
TextStyle(color: Theme.of(context).colorScheme.onPrimary),
),
).ripple(
() {
if (onActionPressed != null) onActionPressed!();
},
borderRadius: BorderRadius.circular(40),
),
)
: icon == null
? Container()
: IconButton(
onPressed: () {
if (onActionPressed != null) onActionPressed!();
},
icon: customIcon(context,
icon: icon!,
isTwitterIcon: true,
iconColor: AppColor.primary,
size: 25),
)
];
}
Widget _getUserAvatar(BuildContext context) {
var authState = Provider.of<AuthState>(context);
return Padding(
padding: const EdgeInsets.all(10),
child: CircularImage(
path: authState.userModel?.profilePic,
height: 30,
).ripple(() {
scaffoldKey!.currentState!.openDrawer();
}),
);
}
@override
Widget build(BuildContext context) {
return AppBar(
iconTheme: const IconThemeData(color: Colors.blue),
backgroundColor: Colors.white,
leading: isBackButton
? const BackButton()
: isCrossButton
? IconButton(
icon: const Icon(Icons.close),
onPressed: () {
Navigator.pop(context);
},
)
: _getUserAvatar(context),
title: title ?? _searchField(),
actions: _getActionButtons(context),
bottom: PreferredSize(
child: Container(
color: isBottomLine
? Colors.grey.shade200
: Theme.of(context).scaffoldBackgroundColor,
height: 1.0,
),
preferredSize: const Size.fromHeight(0.0),
),
);
}
}