Skip to content

Commit 82793f8

Browse files
committed
🐛(fix) InitialRoute error
#36 (comment)
1 parent 648b66b commit 82793f8

File tree

8 files changed

+155
-95
lines changed

8 files changed

+155
-95
lines changed

lib/helper/customRoute.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CustomRoute<T> extends MaterialPageRoute<T> {
1111
Widget buildTransitions(BuildContext context, Animation<double> animation,
1212
Animation<double> secondaryAnimation, Widget child) {
1313
Routes.sendNavigationEventToFirebase(settings.name);
14-
if (settings.isInitialRoute) {
14+
if (settings.name == "SplashPage") {
1515
return child;
1616
}
1717
return FadeTransition(
@@ -28,7 +28,7 @@ class SlideLeftRoute<T> extends MaterialPageRoute<T> {
2828
Widget buildTransitions(BuildContext context, Animation<double> animation,
2929
Animation<double> secondaryAnimation, Widget child) {
3030
Routes.sendNavigationEventToFirebase(settings.name);
31-
if (settings.isInitialRoute) {
31+
if (settings.name == "SplashPage"){
3232
return child;
3333
}
3434
return SlideTransition(

lib/helper/routes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import '../widgets/customWidgets.dart';
3737
class Routes{
3838
static dynamic route(){
3939
return {
40-
'/': (BuildContext context) => SplashPage(),
40+
'SplashPage': (BuildContext context) => SplashPage(),
4141
};
4242
}
4343

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MyApp extends StatelessWidget {
4141
routes: Routes.route(),
4242
onGenerateRoute: (settings) => Routes.onGenerateRoute(settings),
4343
onUnknownRoute: (settings) => Routes.onUnknownRoute(settings),
44+
initialRoute: "SplashPage",
4445
),
4546
);
4647
}

lib/page/profile/EditProfilePage.dart

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import 'dart:io';
2-
32
import 'package:flutter/material.dart';
43
import 'package:flutter_twitter_clone/helper/utility.dart';
5-
import 'package:flutter_twitter_clone/model/user.dart';
64
import 'package:flutter_twitter_clone/state/authState.dart';
75
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
86
import 'package:provider/provider.dart';
@@ -33,34 +31,38 @@ class _EditProfilePageState extends State<EditProfilePage> {
3331
_dob.text = getdob(state?.userModel?.dob);
3432
super.initState();
3533
}
36-
void dispose() {
34+
35+
void dispose() {
3736
_name.dispose();
3837
_bio.dispose();
3938
_location.dispose();
4039
_dob.dispose();
4140
super.dispose();
4241
}
42+
4343
Widget _body() {
44-
var authstate = Provider.of<AuthState>(context);
44+
var authstate = Provider.of<AuthState>(context, listen: false);
4545
return Column(
4646
crossAxisAlignment: CrossAxisAlignment.start,
4747
children: <Widget>[
4848
Container(
49-
height: 180,
50-
child: Stack(
51-
children: <Widget>[
52-
Padding(
53-
padding: EdgeInsets.only(top: 0),
54-
child: customNetworkImage(
55-
'https://pbs.twimg.com/profile_banners/457684585/1510495215/1500x500',
56-
fit: BoxFit.fill),
57-
),
58-
Align(
59-
alignment: Alignment.bottomLeft,
60-
child: _userImage(authstate),
61-
),
62-
],
63-
)),
49+
height: 180,
50+
child: Stack(
51+
children: <Widget>[
52+
Container(
53+
height: 180,
54+
padding: EdgeInsets.only(bottom: 50),
55+
child: customNetworkImage(
56+
'https://pbs.twimg.com/profile_banners/457684585/1510495215/1500x500',
57+
fit: BoxFit.fill),
58+
),
59+
Align(
60+
alignment: Alignment.bottomLeft,
61+
child: _userImage(authstate),
62+
),
63+
],
64+
),
65+
),
6466
_entry('Name', controller: _name),
6567
_entry('Bio', controller: _bio, maxLine: null),
6668
_entry('Location', controller: _location),

lib/page/profile/profilePage.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:flutter/gestures.dart';
21
import 'package:flutter/material.dart';
32
import 'package:flutter_twitter_clone/helper/constant.dart';
43
import 'package:flutter_twitter_clone/helper/enum.dart';
@@ -54,8 +53,9 @@ class _ProfilePageState extends State<ProfilePage>
5453
var authstate = Provider.of<AuthState>(context);
5554
return SliverAppBar(
5655
forceElevated: false,
57-
expandedHeight: 180,
56+
expandedHeight: 200,
5857
elevation: 0,
58+
stretch: true,
5959
iconTheme: IconThemeData(color: Colors.white),
6060
backgroundColor: Colors.transparent,
6161
actions: <Widget>[
@@ -74,9 +74,11 @@ class _ProfilePageState extends State<ProfilePage>
7474
),
7575
],
7676
flexibleSpace: FlexibleSpaceBar(
77+
stretchModes: <StretchMode>[StretchMode.zoomBackground, StretchMode.blurBackground],
7778
background: authstate.isbusy
7879
? SizedBox.shrink()
7980
: Stack(
81+
alignment: Alignment.topCenter,
8082
children: <Widget>[
8183
SizedBox.expand(
8284
child: Container(
@@ -85,21 +87,24 @@ class _ProfilePageState extends State<ProfilePage>
8587
color: Colors.white,
8688
),
8789
),
88-
Container(height: 50, color: Colors.black),
90+
// Container(height: 50, color: Colors.black),
8991

9092
/// Banner image
91-
Padding(
92-
padding: EdgeInsets.only(top: 30),
93+
Container(
94+
height: 180,
95+
padding: EdgeInsets.only(top: 28),
9396
child: customNetworkImage(
94-
'https://pbs.twimg.com/profile_banners/457684585/1510495215/1500x500',
95-
fit: BoxFit.fill),
97+
'https://pbs.twimg.com/profile_banners/457684585/1510495215/1500x500',
98+
fit: BoxFit.fill,
99+
),
96100
),
97101

98102
/// User avatar, message icon, profile edit and follow/following button
99103
Container(
100104
alignment: Alignment.bottomLeft,
101105
child: Row(
102106
mainAxisAlignment: MainAxisAlignment.spaceBetween,
107+
crossAxisAlignment: CrossAxisAlignment.end,
103108
children: <Widget>[
104109
AnimatedContainer(
105110
duration: Duration(milliseconds: 500),
@@ -120,7 +125,7 @@ class _ProfilePageState extends State<ProfilePage>
120125
),
121126
),
122127
Container(
123-
margin: EdgeInsets.only(top: 60, right: 30),
128+
margin: EdgeInsets.only(top: 90, right: 30),
124129
child: Row(
125130
children: <Widget>[
126131
isMyProfile
@@ -134,7 +139,8 @@ class _ProfilePageState extends State<ProfilePage>
134139
onPressed: () {
135140
if (!isMyProfile) {
136141
final chatState =
137-
Provider.of<ChatState>(context,
142+
Provider.of<ChatState>(
143+
context,
138144
listen: false);
139145
chatState.setChatUser =
140146
authstate.profileUserModel;
@@ -213,7 +219,7 @@ class _ProfilePageState extends State<ProfilePage>
213219
: isFollower()
214220
? TwitterColor.white
215221
: Colors.blue,
216-
fontSize: 17,
222+
fontSize: 17,
217223
fontWeight: FontWeight.bold,
218224
),
219225
),
@@ -508,6 +514,7 @@ class UserNameRowWidget extends StatelessWidget {
508514
Padding(
509515
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
510516
child: Row(
517+
crossAxisAlignment: CrossAxisAlignment.start,
511518
children: <Widget>[
512519
customIcon(context,
513520
icon: AppIcon.locationPin,
@@ -516,10 +523,12 @@ class UserNameRowWidget extends StatelessWidget {
516523
paddingIcon: 5,
517524
iconColor: AppColor.darkGrey),
518525
SizedBox(width: 10),
519-
customText(
526+
Expanded(
527+
child:customText(
520528
user.location,
521529
style: TextStyle(color: AppColor.darkGrey),
522530
),
531+
)
523532
],
524533
),
525534
),

lib/widgets/customWidgets.dart

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11

22
import 'dart:io';
33

4+
import 'package:cached_network_image/cached_network_image.dart';
45
import 'package:flutter/cupertino.dart';
56
import 'package:flutter/material.dart';
67
import 'package:flutter/widgets.dart';
7-
import 'package:flutter_advanced_networkimage/provider.dart';
8-
import 'package:flutter_twitter_clone/helper/utility.dart';
98
import 'package:flutter_twitter_clone/helper/constant.dart';
109
import 'package:flutter_twitter_clone/helper/theme.dart';
1110
import 'package:image_picker/image_picker.dart';
@@ -133,22 +132,31 @@ SizedBox sizedBox({double height = 5, String title}){
133132
);
134133
}
135134
Widget customNetworkImage(String path,{BoxFit fit = BoxFit.contain}){
136-
return Image(
137-
image: customAdvanceNetworkImage(path),
138-
fit: fit);
135+
return CachedNetworkImage(
136+
fit: fit,
137+
imageUrl: path ?? dummyProfilePic,
138+
imageBuilder: (context, imageProvider) => Container(
139+
decoration: BoxDecoration(
140+
image: DecorationImage(
141+
image: imageProvider,
142+
fit: fit,
143+
),
144+
),
145+
),
146+
placeholderFadeInDuration: Duration(milliseconds: 500),
147+
placeholder: (context, url) => Container(
148+
color: Color(0xffeeeeee),
149+
),
150+
errorWidget: (context, url, error) => Icon(Icons.error),
151+
);
139152
}
140153
dynamic customAdvanceNetworkImage(String path){
141-
return AdvancedNetworkImage(
142-
path ?? dummyProfilePic,
143-
useDiskCache: true,
144-
printError: true,
145-
// fallbackAssetImage: 'assets/images/userIcon.png',
146-
loadFailedCallback: (){
147-
cprint(' Image load failed' + path);
148-
},
149-
cacheRule: CacheRule(
150-
maxAge: const Duration(days: 7)
151-
),);
154+
if(path == null){
155+
path = dummyProfilePic;
156+
}
157+
return CachedNetworkImageProvider(
158+
path ?? dummyProfilePic,
159+
);
152160
}
153161
void showAlert(BuildContext context,{@required Function onPressedOk,@required String title,String okText = 'OK', String cancelText = 'Cancel'}) async{
154162
showDialog(

0 commit comments

Comments
 (0)