update dart code

This commit is contained in:
Motia Benachour 2022-09-11 15:37:28 +01:00
parent 18794c3e04
commit 4bac46aa00
No known key found for this signature in database
GPG key ID: 070D55D6C32CF425
22 changed files with 151 additions and 152 deletions

View file

@ -1,7 +1,7 @@
enum Flavor { MOCK, PRO }
class Injector {
static Flavor _flavor;
static late Flavor _flavor;
static void configure(Flavor flavor) {
_flavor = flavor;

View file

@ -3,8 +3,8 @@ class Expenses {
String amount;
String percentage;
Expenses({
this.type,
this.amount,
this.percentage,
required this.type,
required this.amount,
required this.percentage,
});
}

View file

@ -6,11 +6,11 @@ class HealthSteam {
String oneGramGoldPriceInLira;
HealthSteam({
this.type,
this.valueInPercentage,
this.goldInGram,
this.goldPriceInTurkishLira,
this.oneGramGoldPriceInLira,
required this.type,
required this.valueInPercentage,
required this.goldInGram,
required this.goldPriceInTurkishLira,
required this.oneGramGoldPriceInLira,
});
HealthSteam.fromJson(Map<dynamic, dynamic> map)

View file

@ -1,7 +1,8 @@
class Category {
String name;
String color;
Category({this.name, this.color});
Category({required this.name, required this.color});
Category.formJson(Map<String, dynamic> map)
: name = map["name"],
@ -16,7 +17,11 @@ class Transaction {
Category category;
Transaction(
{this.amount, this.description, this.date, this.name, this.category});
{required this.amount,
required this.description,
required this.date,
required this.name,
required this.category});
Transaction.fromJson(Map<String, dynamic> map)
: category = Category.formJson(map["category"]),

View file

@ -4,5 +4,11 @@ class User {
String email;
String token;
User({this.userId, this.name, this.email, this.token});
static final User noUser = User(userId: 0, name: '', email: '', token: '');
User(
{required this.userId,
required this.name,
required this.email,
required this.token});
}

View file

@ -11,14 +11,16 @@ class Wallet {
List<HealthSteam> healthStreams;
List<Expenses> expensesChart;
static final Wallet emptyWallet = Wallet._empty();
Wallet({
this.totalAssets,
this.totalTurkishLiraPool,
this.totalGoldInGram,
this.totalGoldInTurkishLira,
this.healthSteamDay,
this.healthStreams,
this.expensesChart,
required this.totalAssets,
required this.totalTurkishLiraPool,
required this.totalGoldInGram,
required this.totalGoldInTurkishLira,
required this.healthSteamDay,
required this.healthStreams,
required this.expensesChart,
});
Wallet.fromMap(Map<String, dynamic> map)
@ -29,5 +31,15 @@ class Wallet {
healthSteamDay = map["health_stream_day"],
healthStreams = (map["health_stream"] as List)
.map((i) => HealthSteam.fromJson(i))
.toList();
.toList(),
expensesChart = [];
Wallet._empty():
totalAssets = '',
totalTurkishLiraPool = '',
totalGoldInGram = '',
totalGoldInTurkishLira = '',
healthSteamDay = '',
healthStreams = [],
expensesChart = [];
}

View file

@ -18,7 +18,7 @@ class AuthProvider with ChangeNotifier {
Status get loggedInStatus => _loggedInStatus;
Status get registeredInStatus => _registeredInStatus;
Future<Map<String, dynamic>> login(String email, int pinCode) async {
Future login(String email, int pinCode) async {
var result;
final Map<String, dynamic> loginData = {

View file

@ -3,32 +3,28 @@ import 'package:robo_advisory/models/transaction.dart';
import 'package:robo_advisory/repository/transaction.repository.dart';
class TransactionProvider with ChangeNotifier {
String _selectedCategory = "All";
List<Transaction> _transactionsData;
List<Transaction> _transactionsList;
String? _selectedCategory;
List<Transaction> _transactionsData = [];
List<Transaction> get transactionList {
if (_selectedCategory != 'All') {
return _transactionsList = _transactionsData
.where((transaction) =>
transaction.category.name == _selectedCategory.toLowerCase())
.toList();
} else {
return _transactionsList = _transactionsData;
if (_selectedCategory == null) {
return _transactionsData;
}
return _transactionsData
.where((transaction) =>
transaction.category.name == _selectedCategory?.toLowerCase())
.toList();
}
void setTransactionsList(List<Transaction> transactions) {
_transactionsData = transactions;
_transactionsList = transactions;
notifyListeners();
}
String get selectedCategory => _selectedCategory;
String? get selectedCategory => _selectedCategory;
void setSelectedCategory(String category) {
void setSelectedCategory(String? category) {
_selectedCategory = category;
print(_selectedCategory);
notifyListeners();
}

View file

@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:robo_advisory/models/user.dart';
class UserProvider with ChangeNotifier {
User _user = new User();
User _user = User.noUser;
int _selectedTabIndex = 0;
List<String> _categories = ["All", "Workplace", "Equipment", "Home", "Other"];

View file

@ -3,7 +3,7 @@ import 'package:robo_advisory/models/wallet.dart';
import 'package:robo_advisory/repository/wallet.repository.dart';
class WalletProvider with ChangeNotifier {
Wallet _wallet = new Wallet();
Wallet _wallet = Wallet.emptyWallet;
Wallet get wallet => _wallet;

View file

@ -17,7 +17,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
void _openEndDrawer() {
_scaffoldKey.currentState.openEndDrawer();
_scaffoldKey.currentState?.openEndDrawer();
}
@override

View file

@ -3,7 +3,7 @@ import 'package:robo_advisory/theme/icons.dart';
import 'package:flutter_svg/flutter_svg.dart';
class BottomNavigation extends StatelessWidget {
BottomNavigation({@required this.selectedIndex, @required this.onItemTapped});
BottomNavigation({required this.selectedIndex, required this.onItemTapped});
final int selectedIndex;
final Function onItemTapped;
@override
@ -48,7 +48,7 @@ class BottomNavigation extends StatelessWidget {
showSelectedLabels: false,
showUnselectedLabels: false,
currentIndex: selectedIndex,
onTap: onItemTapped,
onTap: (v) => onItemTapped(v),
);
}
}

View file

@ -17,13 +17,12 @@ class HistoryScreen extends StatefulWidget {
class _HistoryScreenState extends State<HistoryScreen> {
bool loadingData = true;
List<Transaction> transactionData;
List<Transaction> transactionData = [];
void initState() {
TransactionProvider transactionProvider =
Provider.of<TransactionProvider>(context, listen: false);
transactionProvider.loadTransactions().then((value) {
if (value != null) {
Timer(Duration(seconds: 3), () {
setState(() {
loadingData = false;
@ -32,9 +31,6 @@ class _HistoryScreenState extends State<HistoryScreen> {
.setTransactionsList(transactionData);
});
});
}
print(value);
});
super.initState();
}
@ -72,8 +68,9 @@ class _HistoryScreenState extends State<HistoryScreen> {
hint: new Text("Select Category"),
value: Provider.of<TransactionProvider>(context,
listen: true)
.selectedCategory,
onChanged: (String newValue) {
.selectedCategory ??
'All',
onChanged: (String? newValue) {
Provider.of<TransactionProvider>(context,
listen: false)
.setSelectedCategory(newValue);

View file

@ -4,7 +4,9 @@ import 'package:robo_advisory/utils/helpers.dart';
class TransactionListTile extends StatelessWidget {
final Transaction transactionObject;
TransactionListTile({this.transactionObject});
TransactionListTile({required this.transactionObject});
@override
Widget build(BuildContext context) {
return Column(

View file

@ -12,7 +12,7 @@ import 'package:robo_advisory/screens/home/local_widgets/expenses_chart.dart';
import 'dart:async';
class HomeScreen extends StatefulWidget {
HomeScreen({@required this.toggleDrawer});
HomeScreen({required this.toggleDrawer});
final Function toggleDrawer;
@override
_HomeScreenState createState() => _HomeScreenState();
@ -20,13 +20,13 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
bool loadingData = true;
Wallet walletData;
Wallet walletData = Wallet.emptyWallet;
void initState() {
WalletProvider walletProvider =
Provider.of<WalletProvider>(context, listen: false);
walletProvider.loadWallet().then((value) {
if (value.totalAssets != null) {
if (value.totalAssets.isNotEmpty) {
Timer(Duration(seconds: 3), () {
setState(() {
loadingData = false;
@ -70,7 +70,7 @@ class _HomeScreenState extends State<HomeScreen> {
),
),
GestureDetector(
onTap: widget.toggleDrawer,
onTap: () => widget.toggleDrawer(),
child: Icon(Icons.more_vert),
),
],

View file

@ -10,7 +10,7 @@ class ExpensesChart extends StatefulWidget {
}
class ExpensesChartState extends State {
int touchedIndex;
int? touchedIndex;
@override
Widget build(BuildContext context) {
@ -21,18 +21,22 @@ class ExpensesChartState extends State {
Expanded(
child: PieChart(
PieChartData(
pieTouchData: PieTouchData(touchCallback: (pieTouchResponse) {
pieTouchData:
PieTouchData(touchCallback: (event, pieTouchResponse) {
if (pieTouchResponse == null) return;
setState(() {
if (pieTouchResponse.touchInput is FlLongPressEnd ||
pieTouchResponse.touchInput is FlPanEnd) {
if (event is FlLongPressEnd || event is FlPanEndEvent) {
touchedIndex = -1;
} else {
touchedIndex = pieTouchResponse.touchedSectionIndex;
touchedIndex =
pieTouchResponse.touchedSection?.touchedSectionIndex;
if (touchedIndex != null) {
Provider.of<UserProvider>(context, listen: false)
.setSelectedTabIndex(3);
Provider.of<TransactionProvider>(context, listen: false)
.setSelectedCategory(categories[touchedIndex + 1]);
.setSelectedCategory(categories[touchedIndex! + 1]);
}
}
});
@ -50,58 +54,31 @@ class ExpensesChartState extends State {
}
List<PieChartSectionData> showingSections() {
return List.generate(4, (i) {
final isTouched = i == touchedIndex;
final colorsDict = [0xff0293ee, 0xfff8b250, 0xff13d38e, 0xff845bef];
final values = [50.0, 12.0, 13.0, 25.0];
return values
.asMap()
.entries
.map((entry) => _pieChartSectionData(
colorsDict[entry.key], entry.value, touchedIndex == entry.key))
.toList();
}
PieChartSectionData _pieChartSectionData(
int color, double value, bool isTouched) {
final double fontSize = isTouched ? 25 : 16;
final double radius = isTouched ? 60 : 50;
switch (i) {
case 0:
return PieChartSectionData(
color: const Color(0xff0293ee),
value: 50,
title: '50%',
color: Color(color),
value: value,
title: value.toString() + '%',
radius: radius,
titleStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: const Color(0xffffffff)),
);
case 1:
return PieChartSectionData(
color: const Color(0xfff8b250),
value: 12,
title: '12%',
radius: radius,
titleStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: const Color(0xffffffff)),
);
case 2:
return PieChartSectionData(
color: const Color(0xff13d38e),
value: 13,
title: '13%',
radius: radius,
titleStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: const Color(0xffffffff)),
);
case 3:
return PieChartSectionData(
color: const Color(0xff845bef),
value: 25,
title: '25%',
radius: radius,
titleStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.bold,
color: const Color(0xffffffff)),
);
default:
return null;
}
});
}
}

View file

@ -4,7 +4,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
class FinancialHealthStream extends StatelessWidget {
FinancialHealthStream({@required this.healthSteams});
FinancialHealthStream({required this.healthSteams});
final List<HealthSteam> healthSteams;
double calculatePercentage(double fullWidth, int percentValue) {

View file

@ -76,6 +76,7 @@ class LoginScreen extends StatelessWidget {
Padding(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: PinCodeTextField(
appContext: context,
length: 5,
cursorColor: Colors.black,
animationType: AnimationType.fade,

View file

@ -44,6 +44,7 @@ class RegisterFirstScreen extends StatelessWidget {
Padding(
padding: EdgeInsets.only(left: 10.0, right: 10.0),
child: PinCodeTextField(
appContext: context,
length: 5,
cursorColor: Colors.black,
backgroundColor: Colors.white,
@ -75,6 +76,7 @@ class RegisterFirstScreen extends StatelessWidget {
scale: 0.8,
child: Switch(
value: false,
onChanged: (_) {},
),
),
Text('Remember me')

View file

@ -14,7 +14,7 @@ final otpPinTheme = PinTheme(
fieldWidth: 50,
);
InputDecoration roboInputDecoration({String placeholderHint}) {
InputDecoration roboInputDecoration({String? placeholderHint}) {
return InputDecoration(
filled: true,
fillColor: Colors.white,

View file

@ -1,30 +1,30 @@
import 'package:flutter/material.dart';
class SizeConfig {
static MediaQueryData _mediaQueryData;
static double screenWidth;
static double screenHeight;
static double defaultSize;
static Orientation orientation;
void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
orientation = _mediaQueryData.orientation;
}
}
// Get the proportionate height as per screen size
double getProportionateScreenHeight(double inputHeight) {
double screenHeight = SizeConfig.screenHeight;
// 812 is the layout height that designer use
return (inputHeight / 812.0) * screenHeight;
}
// Get the proportionate height as per screen size
double getProportionateScreenWidth(double inputWidth) {
double screenWidth = SizeConfig.screenWidth;
// 375 is the layout width that designer use
return (inputWidth / 375.0) * screenWidth;
}
// import 'package:flutter/material.dart';
//
// class SizeConfig {
// static MediaQueryData _mediaQueryData;
// static double screenWidth;
// static double screenHeight;
// static double defaultSize;
// static Orientation orientation;
//
// void init(BuildContext context) {
// _mediaQueryData = MediaQuery.of(context);
// screenWidth = _mediaQueryData.size.width;
// screenHeight = _mediaQueryData.size.height;
// orientation = _mediaQueryData.orientation;
// }
// }
//
// // Get the proportionate height as per screen size
// double getProportionateScreenHeight(double inputHeight) {
// double screenHeight = SizeConfig.screenHeight;
// // 812 is the layout height that designer use
// return (inputHeight / 812.0) * screenHeight;
// }
//
// // Get the proportionate height as per screen size
// double getProportionateScreenWidth(double inputWidth) {
// double screenWidth = SizeConfig.screenWidth;
// // 375 is the layout width that designer use
// return (inputWidth / 375.0) * screenWidth;
// }

View file

@ -46,6 +46,7 @@ class AppDrawer extends StatelessWidget {
_createDrawerItem(
icon: accountIcon,
text: 'Account',
onTap: () {},
),
_createDrawerItem(
icon: logoutIcon,
@ -125,7 +126,7 @@ class AppDrawer extends StatelessWidget {
}
Widget _createDrawerItem(
{String icon, String text, GestureTapCallback onTap}) {
{required String icon, required String text, required GestureTapCallback onTap}) {
return ListTile(
title: Row(
children: <Widget>[