Skip to content

Commit

Permalink
Merge pull request #198 from vrrao01/upgrader
Browse files Browse the repository at this point in the history
Upgrader
  • Loading branch information
vrrao01 authored Jan 14, 2023
2 parents 3e4c772 + c668f3f commit 154b987
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 58 deletions.
54 changes: 28 additions & 26 deletions lib/pages/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:onestop_dev/pages/travel/travel.dart';
import 'package:onestop_dev/stores/mapbox_store.dart';
import 'package:onestop_dev/stores/timetable_store.dart';
import 'package:onestop_dev/widgets/ui/appbar.dart';
import 'package:onestop_dev/widgets/ui/onestop_upgrade.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
Expand All @@ -29,38 +30,39 @@ class _HomePageState extends State<HomePage> {
const TravelPage(),
const TimeTableTab(),
];

@override
Widget build(BuildContext context) {
SizeConfig().init(context);
return Provider(
create: (_) => TimetableStore(),
child: Scaffold(
appBar: appBar(context),
bottomNavigationBar: NavigationBarTheme(
data: NavigationBarThemeData(
indicatorColor: lGrey,
labelTextStyle:
MaterialStateProperty.all(MyFonts.w500.setColor(kTabText)),
iconTheme: MaterialStateProperty.all(
const IconThemeData(color: kTabText))),
child: NavigationBar(
backgroundColor: kTabBar,
selectedIndex: index,
onDestinationSelected: (index) => setState(() {
this.index = index;
context.read<MapBoxStore>().mapController = null;
}),
destinations: bottomNavIcons(),
return OneStopUpgrader(
child: Provider(
create: (_) => TimetableStore(),
child: Scaffold(
appBar: appBar(context),
bottomNavigationBar: NavigationBarTheme(
data: NavigationBarThemeData(
indicatorColor: lGrey,
labelTextStyle:
MaterialStateProperty.all(MyFonts.w500.setColor(kTabText)),
iconTheme: MaterialStateProperty.all(
const IconThemeData(color: kTabText))),
child: NavigationBar(
backgroundColor: kTabBar,
selectedIndex: index,
onDestinationSelected: (index) => setState(() {
this.index = index;
context.read<MapBoxStore>().mapController = null;
}),
destinations: bottomNavIcons(),
),
),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: tabs[index],
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: tabs[index],
),
),
floatingActionButton: homeActionButton(context, index),
),
floatingActionButton: homeActionButton(context, index),
),
);
}
Expand Down
76 changes: 44 additions & 32 deletions lib/widgets/home/home_tab_tile.dart
Original file line number Diff line number Diff line change
@@ -1,53 +1,65 @@
import 'package:badges/badges.dart';
import 'package:flutter/material.dart';
import 'package:onestop_dev/globals/my_colors.dart';
import 'package:onestop_dev/globals/my_fonts.dart';

class HomeTabTile extends StatelessWidget {
const HomeTabTile(
{Key? key, required this.label, required this.icon, this.routeId})
{Key? key, required this.label, required this.icon, this.routeId, this.newBadge = false})
: super(key: key);

final String label;
final IconData icon;
final String? routeId;
final bool newBadge;

@override
Widget build(BuildContext context) {
return Expanded(
child: FittedBox(
child: GestureDetector(
onTap: () => Navigator.pushNamed(context, routeId ?? "/"),
child: Container(
//margin: EdgeInsets.all(4),
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50), color: lGrey),
padding: const EdgeInsets.all(4.0),
child: Column(
// Replace with a Row for horizontal icon + text
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const SizedBox(
height: 8,
),
Expanded(
child: Icon(
icon,
size: 40,
color: lBlue,
),
),
Expanded(
child: Text(label,
style: MyFonts.w500.size(23).setColor(lBlue),
textAlign: TextAlign.center),
Widget finalWidget = FittedBox(
child: GestureDetector(
onTap: () => Navigator.pushNamed(context, routeId ?? "/"),
child: Container(
//margin: EdgeInsets.all(4),
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50), color: lGrey),
padding: const EdgeInsets.all(4.0),
child: Column(
// Replace with a Row for horizontal icon + text
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const SizedBox(
height: 8,
),
Expanded(
child: Icon(
icon,
size: 40,
color: lBlue,
),
],
),
),
Expanded(
child: Text(label,
style: MyFonts.w500.size(23).setColor(lBlue),
textAlign: TextAlign.center),
),
],
),
),
),
);
if (newBadge) {
finalWidget = Badge(
shape: BadgeShape.square,
borderRadius: BorderRadius.circular(8),
badgeContent: Text('New', style: MyFonts.w600.setColor(Color.fromRGBO(62, 71, 88, 1)).size(10),),
badgeColor: Color.fromRGBO(255, 201, 7, 1),
child:finalWidget,
);
}
return Expanded(
child: finalWidget,
);
}
}
1 change: 1 addition & 0 deletions lib/widgets/home/service_links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ List<HomeTabTile> serviceLinks = [
label: "GC Score Board",
icon: FluentIcons.trophy_20_regular,
routeId: Scoreboard.id,
newBadge: true,
),
];
48 changes: 48 additions & 0 deletions lib/widgets/ui/onestop_upgrade.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:onestop_dev/globals/my_colors.dart';
import 'package:onestop_dev/globals/my_fonts.dart';
import 'package:upgrader/upgrader.dart';


class OneStopUpgraderMessages extends UpgraderMessages {
@override
String get title => 'OneStop Update Available';
@override
String get body => 'OneStop v{{currentAppStoreVersion}} is now available. You are on a previous version - v{{currentInstalledVersion}}';
}


class OneStopUpgrader extends StatelessWidget {
final Widget child;
const OneStopUpgrader({Key? key, required this.child}) : super(key: key);

@override
Widget build(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
dialogTheme: DialogTheme(
backgroundColor: kBackground,
titleTextStyle: MyFonts.w600.setColor(lBlue).size(20),
contentTextStyle: MyFonts.w400.setColor(lBlue),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: lBlue2,
textStyle: MyFonts.w600
)
)
),
child: UpgradeAlert(
upgrader: Upgrader(
countryCode: 'IN',
durationUntilAlertAgain: const Duration(hours: 1),
debugDisplayAlways: true,
showIgnore: false,
messages: OneStopUpgraderMessages(),
),
child: child
),
);
}
}

3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ dependencies:
path_provider: ^2.0.11
path: ^1.8.0
infinite_scroll_pagination: ^3.2.0
upgrader: ^5.1.0
badges: ^2.0.3


dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 154b987

Please sign in to comment.