Skip to content

Commit 382b581

Browse files
committed
GFAppBar and with search bar completed
1 parent 8ff490e commit 382b581

4 files changed

Lines changed: 128 additions & 122 deletions

File tree

example/lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import 'package:getflutter/components/tabs/gf_tabs.dart';
2222
import 'package:getflutter/components/tabs/gf_tabBarView.dart';
2323
import 'package:getflutter/types/gf_button_type.dart';
2424
import 'package:getflutter/position/gf_position.dart';
25-
import 'dart:io';
2625

2726
final List<String> imageList = [
2827
"https://cdn.pixabay.com/photo/2017/12/03/18/04/christmas-balls-2995437_960_720.jpg",
@@ -166,7 +165,7 @@ class _MyHomePageState extends State<MyHomePage>
166165
// searchBarColorTheme: Colors.greenAccent,
167166

168167
actions: <Widget>[
169-
GFIconButton(icon: Icon(Icons.access_time), onPressed: (){}),
168+
GFIconButton(icon: Icon(Icons.access_time), onPressed: () {}),
170169
GFIconButton(icon: Icon(Icons.favorite), onPressed: null),
171170
],
172171
),

lib/components/appbar/gf_appbar.dart

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import 'package:flutter/rendering.dart';
33
import 'package:flutter/services.dart';
44
import 'package:flutter/widgets.dart';
55
import 'package:flutter/material.dart';
6-
import 'package:getflutter/components/button/gf_icon_button.dart';
7-
import 'package:getflutter/components/search_bar/gf_search_bar.dart';
86
import 'package:getflutter/getflutter.dart';
97

108
/// An app bar consists of a toolbar and potentially other widgets, such as a
@@ -47,7 +45,9 @@ class GFAppBar extends StatefulWidget implements PreferredSizeWidget {
4745
this.searchBar = false,
4846
this.searchHintText = 'Search...',
4947
this.searchHintStyle = const TextStyle(color: Colors.white, fontSize: 14.0),
50-
this.searchTextStyle = const TextStyle(color: Colors.white,),
48+
this.searchTextStyle = const TextStyle(
49+
color: Colors.white,
50+
),
5151
this.searchBarColorTheme = Colors.white,
5252
this.searchController,
5353
this.onTap,
@@ -408,48 +408,62 @@ class _GFAppBarState extends State<GFAppBar> {
408408
);
409409
}
410410

411-
searchBar = ListTile(
412-
contentPadding: EdgeInsets.zero,
413-
title: TextField(
414-
cursorColor: widget.searchBarColorTheme,
415-
style: widget.searchTextStyle,
416-
decoration: new InputDecoration(
417-
prefixIcon: new Icon(Icons.search, color: widget.searchBarColorTheme, size: 18.0,),
418-
hintText: widget.searchHintText,
419-
hintStyle: widget.searchHintStyle,
420-
focusedBorder: UnderlineInputBorder(
421-
borderSide: BorderSide(width: 1, color: widget.searchBarColorTheme),
422-
),
411+
searchBar = ListTile(
412+
contentPadding: EdgeInsets.zero,
413+
title: TextField(
414+
cursorColor: widget.searchBarColorTheme,
415+
style: widget.searchTextStyle,
416+
decoration: new InputDecoration(
417+
prefixIcon: new Icon(
418+
Icons.search,
419+
color: widget.searchBarColorTheme,
420+
size: 18.0,
421+
),
422+
hintText: widget.searchHintText,
423+
hintStyle: widget.searchHintStyle,
424+
focusedBorder: UnderlineInputBorder(
425+
borderSide: BorderSide(width: 1, color: widget.searchBarColorTheme),
423426
),
424-
onTap: widget.onTap,
425-
onChanged: widget.onChanged,
426-
controller: widget.searchController,
427-
onSubmitted: widget.onSubmitted,
428427
),
428+
onTap: widget.onTap,
429+
onChanged: widget.onChanged,
430+
controller: widget.searchController,
431+
onSubmitted: widget.onSubmitted,
432+
),
433+
trailing: GFIconButton(
434+
icon: Icon(
435+
Icons.close,
436+
color: widget.searchBarColorTheme,
437+
size: 20.0,
438+
),
439+
type: GFButtonType.transparent,
440+
onPressed: () {
441+
setState(() {
442+
showSearchBar = !showSearchBar;
443+
});
444+
},
445+
),
446+
);
447+
448+
if (!showSearchBar) {
449+
searchBar = ListTile(
450+
contentPadding: EdgeInsets.zero,
451+
title: title,
429452
trailing: GFIconButton(
430-
icon: Icon(Icons.close, color: widget.searchBarColorTheme, size: 20.0,), type: GFButtonType.transparent,
431-
onPressed: (){
453+
icon: Icon(
454+
Icons.search,
455+
color: widget.searchBarColorTheme,
456+
size: 20.0,
457+
),
458+
type: GFButtonType.transparent,
459+
onPressed: () {
432460
setState(() {
433461
showSearchBar = !showSearchBar;
434462
});
435463
},
436464
),
437465
);
438-
439-
if(!showSearchBar){
440-
searchBar = ListTile(
441-
contentPadding: EdgeInsets.zero,
442-
title: title,
443-
trailing: GFIconButton(
444-
icon: Icon(Icons.search, color: widget.searchBarColorTheme, size: 20.0,), type: GFButtonType.transparent,
445-
onPressed: (){
446-
setState(() {
447-
showSearchBar = !showSearchBar;
448-
});
449-
},
450-
),
451-
);
452-
}
466+
}
453467

454468
final Widget toolbar = NavigationToolbar(
455469
leading: leading,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
import 'package:flutter/material.dart';
21

lib/components/toggle/gf_toggle.dart

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GFToggle extends StatefulWidget {
1616
GFToggle(
1717
{Key key,
1818
@required this.onChanged,
19-
this.value ,
19+
this.value,
2020
this.enabledText,
2121
this.disabledText,
2222
this.enabledTextStyle,
@@ -73,7 +73,6 @@ class GFToggle extends StatefulWidget {
7373
/// Called when the user toggles the switch on or off.
7474
final ValueChanged<bool> onChanged;
7575

76-
7776
@override
7877
_GFToggleState createState() => _GFToggleState();
7978
}
@@ -86,15 +85,15 @@ class _GFToggleState extends State<GFToggle> with TickerProviderStateMixin {
8685

8786
bool isOn;
8887

89-
90-
9188
@override
9289
void initState() {
9390
setState(() {
94-
isOn = widget.value??false;
91+
isOn = widget.value ?? false;
9592
});
9693
controller = AnimationController(vsync: this, duration: widget.duration);
97-
offset = (isOn?Tween<Offset>(begin: Offset(1.0, 0.0), end:Offset.zero):Tween<Offset>(begin: Offset.zero, end: Offset(1.0, 0.0)))
94+
offset = (isOn
95+
? Tween<Offset>(begin: Offset(1.0, 0.0), end: Offset.zero)
96+
: Tween<Offset>(begin: Offset.zero, end: Offset(1.0, 0.0)))
9897
.animate(controller);
9998
super.initState();
10099
}
@@ -106,8 +105,8 @@ class _GFToggleState extends State<GFToggle> with TickerProviderStateMixin {
106105
super.dispose();
107106
}
108107

109-
void onStatusChange(){
110-
if(widget.onChanged!=null){
108+
void onStatusChange() {
109+
if (widget.onChanged != null) {
111110
setState(() {
112111
isOn = !isOn;
113112
});
@@ -127,84 +126,79 @@ class _GFToggleState extends State<GFToggle> with TickerProviderStateMixin {
127126

128127
@override
129128
Widget build(BuildContext context) {
130-
return Stack(
131-
children: <Widget>[
132-
Container(
133-
height: widget.type == GFToggleType.android ? 25 : 30,
134-
width: widget.type == GFToggleType.android ? 40 : 50,
135-
),
136-
Positioned(
137-
top: 5,
138-
child: InkWell(
129+
return Stack(
130+
children: <Widget>[
131+
Container(
132+
height: widget.type == GFToggleType.android ? 25 : 30,
133+
width: widget.type == GFToggleType.android ? 40 : 50,
134+
),
135+
Positioned(
136+
top: 5,
137+
child: InkWell(
139138
onTap: onStatusChange,
140139
child: Container(
141-
width: widget.type == GFToggleType.ios ? 45 : 36,
142-
height: widget.type == GFToggleType.ios ? 25 : 15,
143-
decoration: BoxDecoration(
144-
color: isOn
145-
? widget.enabledTrackColor ?? Colors.lightGreen
146-
: widget.disabledTrackColor ?? Colors.grey,
147-
borderRadius: widget.type == GFToggleType.square
148-
? BorderRadius.all(Radius.circular(0))
149-
: widget.borderRadius ??
140+
width: widget.type == GFToggleType.ios ? 45 : 36,
141+
height: widget.type == GFToggleType.ios ? 25 : 15,
142+
decoration: BoxDecoration(
143+
color: isOn
144+
? widget.enabledTrackColor ?? Colors.lightGreen
145+
: widget.disabledTrackColor ?? Colors.grey,
146+
borderRadius: widget.type == GFToggleType.square
147+
? BorderRadius.all(Radius.circular(0))
148+
: widget.borderRadius ??
150149
BorderRadius.all(Radius.circular(20))),
151-
child: Padding(
152-
padding: widget.type == GFToggleType.ios
153-
? EdgeInsets.only(left: 3.5, right: 3.5, top: 5.4)
154-
: EdgeInsets.only(left: 3, right: 3, top: 3.4),
155-
child: isOn
156-
? Text(
157-
widget.enabledText ??
158-
(widget.type == GFToggleType.custom
159-
? 'ON'
160-
: ''),
161-
style: widget.enabledTextStyle ??
162-
(widget.type == GFToggleType.ios
163-
? TextStyle(
164-
color: Colors.white, fontSize: 12)
165-
: TextStyle(
166-
color: Colors.white, fontSize: 8)))
167-
: Text(
168-
widget.disabledText ??
169-
(widget.type == GFToggleType.custom
170-
? 'OFF'
171-
: ''),
172-
textAlign: TextAlign.end,
173-
style: widget.disabledTextStyle ??
174-
(widget.type == GFToggleType.ios
175-
? TextStyle(color: Colors.white, fontSize: 12)
176-
: TextStyle(color: Colors.white, fontSize: 8)),),),),
177-
),),
178-
Positioned(
179-
top: widget.type == GFToggleType.ios ? 7.5 : 3,
180-
left: widget.type == GFToggleType.ios ? 2 : 0,
181-
child: InkWell(
182-
onTap: onStatusChange,
183-
child: SlideTransition(
184-
position:offset,
185-
child: Container(
186-
padding: EdgeInsets.only(left: 10),
187-
height: 20,
188-
width: 20,
189-
decoration: BoxDecoration(
190-
shape: widget.type == GFToggleType.square
191-
? BoxShape.rectangle
192-
: widget.boxShape ?? BoxShape.circle,
193-
color: isOn
194-
? widget.enabledThumbColor ?? Colors.white
195-
: widget.disabledThumbColor ?? Colors.white,
196-
boxShadow: [
197-
new BoxShadow(
198-
color: Colors.black.withOpacity(0.16),
199-
blurRadius: 6.0,
200-
spreadRadius: 0.0),
201-
]),
150+
child: Padding(
151+
padding: widget.type == GFToggleType.ios
152+
? EdgeInsets.only(left: 3.5, right: 3.5, top: 5.4)
153+
: EdgeInsets.only(left: 3, right: 3, top: 3.4),
154+
child: isOn
155+
? Text(
156+
widget.enabledText ??
157+
(widget.type == GFToggleType.custom ? 'ON' : ''),
158+
style: widget.enabledTextStyle ??
159+
(widget.type == GFToggleType.ios
160+
? TextStyle(color: Colors.white, fontSize: 12)
161+
: TextStyle(color: Colors.white, fontSize: 8)))
162+
: Text(
163+
widget.disabledText ??
164+
(widget.type == GFToggleType.custom ? 'OFF' : ''),
165+
textAlign: TextAlign.end,
166+
style: widget.disabledTextStyle ??
167+
(widget.type == GFToggleType.ios
168+
? TextStyle(color: Colors.white, fontSize: 12)
169+
: TextStyle(color: Colors.white, fontSize: 8)),
202170
),
203-
)
204-
)),
205-
],
206-
207-
);
171+
),
172+
),
173+
),
174+
),
175+
Positioned(
176+
top: widget.type == GFToggleType.ios ? 7.5 : 3,
177+
left: widget.type == GFToggleType.ios ? 2 : 0,
178+
child: InkWell(
179+
onTap: onStatusChange,
180+
child: SlideTransition(
181+
position: offset,
182+
child: Container(
183+
padding: EdgeInsets.only(left: 10),
184+
height: 20,
185+
width: 20,
186+
decoration: BoxDecoration(
187+
shape: widget.type == GFToggleType.square
188+
? BoxShape.rectangle
189+
: widget.boxShape ?? BoxShape.circle,
190+
color: isOn
191+
? widget.enabledThumbColor ?? Colors.white
192+
: widget.disabledThumbColor ?? Colors.white,
193+
boxShadow: [
194+
new BoxShadow(
195+
color: Colors.black.withOpacity(0.16),
196+
blurRadius: 6.0,
197+
spreadRadius: 0.0),
198+
]),
199+
),
200+
))),
201+
],
202+
);
208203
}
209204
}
210-

0 commit comments

Comments
 (0)