Skip to content

Commit

Permalink
fix: Responsive & Adaptive Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Emon526 committed Nov 29, 2024
1 parent b3a8e49 commit ed3541f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 122 deletions.
50 changes: 4 additions & 46 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import 'package:expense_planner/providers/chartprovider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'pages/home_page.dart';
import 'providers/chartprovider.dart';
import 'providers/themeprovider.dart';
import 'providers/transaction_provider.dart';
import 'theme/theme.dart';

void main() {
//for controlling orientation

// WidgetsFlutterBinding.ensureInitialized();
// SystemChrome.setPreferredOrientations([
// DeviceOrientation.portraitDown,
// DeviceOrientation.portraitUp,
// ]);
runApp(const MyApp());
}

//TODO:: Check Responsive
//TODO:: Check Responsive (100% responsive done)
//TODO:: Remove todo when git push
//TODO:: Git push message (Responsive & Adaptive Theme)
class MyApp extends StatelessWidget {
const MyApp({super.key});

Expand Down Expand Up @@ -47,43 +42,6 @@ class MyApp extends StatelessWidget {
theme: lightTheme,
darkTheme: darkTheme,
themeMode: context.watch<ThemeProvider>().themeMode,
// theme: ThemeData(
// fontFamily: 'Quicksand',
// // textTheme: ThemeData.light().textTheme.copyWith(
// // headline6: TextStyle(
// // fontWeight: FontWeight.bold,
// // fontFamily: 'OpenSans',
// // fontSize: 18,
// // ),
// // button: TextStyle(color: Colors.white),
// // ),
// // appBarTheme: AppBarTheme(
// // toolbarTextStyle: ThemeData.light()
// // .textTheme
// // .copyWith(
// // headline6: TextStyle(
// // fontFamily: 'OpenSans',
// // fontSize: 20,
// // fontWeight: FontWeight.bold,
// // ),
// // )
// // .bodyText2,
// // titleTextStyle: ThemeData.light()
// // .textTheme
// // .copyWith(
// // headline6: TextStyle(
// // fontFamily: 'OpenSans',
// // fontSize: 20,
// // fontWeight: FontWeight.bold,
// // ),
// // )
// // .headline6,
// // ),
// colorScheme:
// ColorScheme.fromSwatch(primarySwatch: Colors.purple).copyWith(
// secondary: Colors.amber,
// ),
// ),
home: HomePage(),
);
},
Expand Down
7 changes: 4 additions & 3 deletions lib/theme/switchthemeadaptation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:flutter/material.dart';
import 'theme.dart';

class SwitchThemeAdaptation extends Adaptation<SwitchThemeData> {
bool isDark = false;
SwitchThemeAdaptation({required this.isDark});
SwitchThemeAdaptation();

@override
SwitchThemeData adapt(ThemeData theme, SwitchThemeData defaultValue) =>
Expand All @@ -26,7 +25,9 @@ class SwitchThemeAdaptation extends Adaptation<SwitchThemeData> {
return null;
}
if (states.contains(WidgetState.selected)) {
return isDark ? secondaryColor : primaryColor;
return theme.brightness == Brightness.dark
? secondaryColor
: primaryColor;
}
return null;
}),
Expand Down
8 changes: 4 additions & 4 deletions lib/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fontFamily = 'Quicksand';
// Use system fonts like Roboto for Android and SF Pro for iOS if you want platform-native experiences
ThemeData lightTheme = ThemeData(
adaptations: <Adaptation<Object>>[
SwitchThemeAdaptation(isDark: false),
SwitchThemeAdaptation(),
// SliderThemeAdaptation(isDark: false),
// CircularProgressIndicatorThemeAdaptation(isDark: false),
// CheckboxThemeAdaptation(isDark: false),
Expand All @@ -30,7 +30,7 @@ ThemeData lightTheme = ThemeData(
),

appBarTheme: AppBarTheme(
centerTitle: true,
// centerTitle: true,
iconTheme: IconThemeData(color: primaryColor),
actionsIconTheme: IconThemeData(color: primaryColor),
),
Expand Down Expand Up @@ -325,7 +325,7 @@ ThemeData lightTheme = ThemeData(

ThemeData darkTheme = ThemeData(
adaptations: <Adaptation<Object>>[
SwitchThemeAdaptation(isDark: true),
SwitchThemeAdaptation(),
// SliderThemeAdaptation(isDark: true),
// CircularProgressIndicatorThemeAdaptation(isDark: true),
// CheckboxThemeAdaptation(isDark: true),
Expand All @@ -345,7 +345,7 @@ ThemeData darkTheme = ThemeData(
selectionHandleColor: secondaryColor,
),
appBarTheme: AppBarTheme(
centerTitle: true,
//centerTitle: true,
iconTheme: IconThemeData(color: secondaryColor),
actionsIconTheme: IconThemeData(color: secondaryColor)),

Expand Down
106 changes: 51 additions & 55 deletions lib/widgets/new_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,64 +70,60 @@ class _NewTransactionState extends State<NewTransaction> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Card(
elevation: 5,
child: Container(
padding: EdgeInsets.only(
top: 20,
left: 20,
right: 20,
bottom: MediaQuery.of(context).viewInsets.bottom + 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
TextField(
decoration: InputDecoration(labelText: 'Title'),
// onChanged: (val) {
// titleInput = val;
// },
controller: titleController,
onSubmitted: (_) => _submitData(),
),
SizedBox(
height: 20,
),
TextField(
decoration: InputDecoration(labelText: 'Amount'),
// onChanged: (val) => amountInput = val,
controller: _amountController,
keyboardType: TextInputType.number,
onSubmitted: (_) => _submitData(),
),
Container(
height: 70,
child: Row(
children: <Widget>[
Expanded(
child: Text(
_selectDate == null
? 'No Date Chosen!'
: 'Picked Date :${DateFormat.yMd().format(_selectDate!)}',
style: TextStyle(
color: Theme.of(context).primaryColor,
),
),
child: Container(
padding: EdgeInsets.only(
top: 20,
left: 20,
right: 20,
bottom: MediaQuery.of(context).viewInsets.bottom + 20,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
TextField(
decoration: InputDecoration(labelText: 'Title'),
controller: titleController,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
textCapitalization: TextCapitalization.sentences,
onSubmitted: (_) => _submitData(),
),
SizedBox(
height: 20,
),
TextField(
decoration: InputDecoration(labelText: 'Amount'),
textInputAction: TextInputAction.next,
controller: _amountController,
keyboardType: TextInputType.number,
// onSubmitted: (_) => _submitData(),
onSubmitted: (_) => _persentDatePicker(),
),
Row(
children: <Widget>[
Expanded(
child: Text(
_selectDate == null
? 'No Date Chosen!'
: 'Picked Date :${DateFormat.yMd().format(_selectDate!)}',
style: TextStyle(
color: Theme.of(context).primaryColor,
),
AdaptiveFlatButton('Choose Date', _persentDatePicker)
],
),
),
AdaptiveFlatButton('Choose Date', _persentDatePicker)
],
),
ElevatedButton(
onPressed: _submitData,
child: Text(
'Add Transaction',
style: TextStyle(
// color: Theme.of(context).textTheme.button.color,
),
),
ElevatedButton(
onPressed: _submitData,
child: Text(
'Add Transaction',
style: TextStyle(
// color: Theme.of(context).textTheme.button.color,
),
),
)
],
),
)
],
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/transaction_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TransactionItem extends StatelessWidget {
),
trailing: MediaQuery.of(context).size.width > 460
? TextButton.icon(
icon: Icon(Icons.delete),
icon: Icon(Icons.delete_outline),
label: Text(
'Delete',
// style: TextStyle(
Expand All @@ -48,7 +48,7 @@ class TransactionItem extends StatelessWidget {
},
)
: IconButton(
icon: Icon(Icons.delete),
icon: Icon(Icons.delete_outline),
// color: Theme.of(context).errorColor,
onPressed: () {
deleteTx();
Expand Down
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: "99f282cb0e02edcbbf8c6b3bbc7c90b65635156c412e58f3975a7e55284ce685"
sha256: "00f33b908655e606b86d2ade4710a231b802eec6f11e87e4ea3783fd72077a50"
url: "https://pub.dev"
source: hosted
version: "0.20.0"
version: "0.20.1"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -545,10 +545,10 @@ packages:
dependency: transitive
description:
name: shelf_web_socket
sha256: "073c147238594ecd0d193f3456a5fe91c4b0abbcc68bf5cd95b36c4e194ac611"
sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.0.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -582,10 +582,10 @@ packages:
dependency: transitive
description:
name: sqflite_common
sha256: "4468b24876d673418a7b7147e5a08a715b4998a7ae69227acafaab762e0e5490"
sha256: "761b9740ecbd4d3e66b8916d784e581861fd3c3553eda85e167bc49fdb68f709"
url: "https://pub.dev"
source: hosted
version: "2.5.4+5"
version: "2.5.4+6"
sqflite_darwin:
dependency: transitive
description:
Expand Down Expand Up @@ -702,10 +702,10 @@ packages:
dependency: transitive
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "1.1.0"
web_socket:
dependency: transitive
description:
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: expense_planner
description: Expese Planner is a flutter project.in this app your can track your weekly expanse.
description: Expese Planner is a flutter project. In this app your can track your weekly,monthly expanse.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
Expand All @@ -18,12 +18,12 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
version: 1.1.1+1

environment:
sdk: ">=3.5.4 <4.0.0"
sdk: ">=3.5.4"

dependencies:
flutter:
sdk: flutter
intl: ^0.20.0
intl: ^0.20.1
sqflite: ^2.4.1

# The following adds the Cupertino Icons font to your application.
Expand All @@ -49,7 +49,7 @@ flutter:

# To add assets to your application, add an assets section, like this:
assets:
- assets/images/slepping.png
- assets/images/
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down

0 comments on commit ed3541f

Please sign in to comment.