11import 'package:flutter/material.dart' ;
22import 'package:flutter_constraintlayout/flutter_constraintlayout.dart' ;
33
4+ import 'code.dart' ;
5+
46class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
57 final double ? height;
68 final Color backgroundColor;
79 final String title;
8- final String leftImg;
9- final GestureTapCallback ? onLeftTap;
10- final GestureTapCallback ? onRightTap;
11- final String ? rightButtonText;
12-
13- static const double DEFAULT_HEIGHT = 64 ;
10+ final String ? codePath;
1411
1512 const CustomAppBar ({
1613 Key ? key,
1714 this .height,
1815 this .backgroundColor = Colors .white,
1916 this .title = '' ,
20- this .leftImg = 'assets/icon_back.webp' ,
21- this .onLeftTap,
22- this .rightButtonText,
23- this .onRightTap,
17+ this .codePath,
2418 }) : super (key: key);
2519
2620 @override
2721 Size get preferredSize {
28- return Size (double .infinity, height ?? DEFAULT_HEIGHT );
22+ return Size (double .infinity, height ?? 64 );
23+ }
24+
25+ void push (BuildContext context, Widget widget) {
26+ Navigator .of (context).push (MaterialPageRoute (builder: (_) {
27+ return widget;
28+ }));
2929 }
3030
3131 @override
3232 Widget build (BuildContext context) {
3333 return Container (
34- height: height ?? DEFAULT_HEIGHT ,
34+ height: height ?? 64 ,
3535 color: backgroundColor,
3636 margin: EdgeInsets .only (
3737 top: MediaQuery .of (context).viewPadding.top,
@@ -40,7 +40,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
4040 children: [
4141 GestureDetector (
4242 child: Image .asset (
43- leftImg ,
43+ 'assets/icon_back.webp' ,
4444 fit: BoxFit .fill,
4545 ),
4646 onTap: () {
@@ -65,7 +65,32 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
6565 ),
6666 ).applyConstraint (
6767 centerTo: parent,
68- )
68+ ),
69+ if (codePath != null )
70+ GestureDetector (
71+ child: const Text (
72+ 'View Code' ,
73+ style: TextStyle (
74+ fontSize: 18 ,
75+ color: Colors .blue,
76+ fontWeight: FontWeight .bold,
77+ ),
78+ ),
79+ onTap: () {
80+ push (
81+ context,
82+ CodeViewWidget (
83+ codePath: codePath! ,
84+ ),
85+ );
86+ },
87+ ).applyConstraint (
88+ centerRightTo: parent,
89+ margin: const EdgeInsets .only (
90+ right: 20 ,
91+ ),
92+ clickPadding: const EdgeInsets .all (20 ),
93+ )
6994 ],
7095 ),
7196 );
0 commit comments