[ad_1]
Hey there Stackverflow Geeks, I need assistance
I configured my App to indicate a swap button in panorama mode, however i cant work out why it isnt working
The next situation ought to assist to me to determine panorama and show a swap which has the perform to show or not show a chart
if (isLandscape)
Row(
mainAxisAlignment: MainAxisAlignment.heart,
kids: [
const Text('Show Chart'),
Switch(
value: _showChart,
onChanged: (value) {
setState(() {
_showChart = value;
});
},
),
],
),
Right here is my full code
import 'bundle:expenses_app/widgets/chart.dart';
import 'bundle:expenses_app/widgets/transacion_list.dart';
import 'bundle:flutter/materials.dart';
// import 'bundle:flutter/companies.dart';
import './widgets/new_transaction.dart';
import './mannequin/transaction.dart';
void predominant() {
// ?power machine to potrait mode
// WidgetsFlutterBinding.ensureInitialized();
// SystemChrome.setPreferredOrientations(
// [
// DeviceOrientation.portraitUp,
// DeviceOrientation.portraitDown,
// ],
// );
runApp(const ExpensesApp());
}
class ExpensesApp extends StatelessWidget {
const ExpensesApp({Key? key}) : tremendous(key: key);
@override
Widget construct(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: ' bills software',
theme: ThemeData(
primarySwatch: Colours.inexperienced,
fontFamily: 'Quicksand',
textTheme: ThemeData.gentle().textTheme.copyWith(
bodyText1: const TextStyle(
fontFamily: 'OpenSans',
fontWeight: FontWeight.daring,
fontSize: 20,
),
button: const TextStyle(
colour: Colours.white,
fontWeight: FontWeight.daring,
),
),
appBarTheme: AppBarTheme(
toolbarTextStyle: ThemeData.gentle().textTheme.copyWith().bodyText2,
titleTextStyle: ThemeData.gentle().textTheme.copyWith().headline6,
),
),
dwelling: const Residence(),
);
}
}
class Residence extends StatefulWidget {
const Residence({Key? key}) : tremendous(key: key);
@override
State<Residence> createState() => _HomeState();
}
class _HomeState extends State<Residence> {
closing Listing<Transaction> _userTransactions = [
// Transaction(
// id: 't1',
// title: 'shoes',
// amount: 345,
// date: DateTime.now(),
// ),
// Transaction(
// id: 't2',
// title: 'eggs',
// amount: 200,
// date: DateTime.now(),
// ),
];
bool _showChart = false;
Listing<Transaction> get _recentTransactions {
return _userTransactions.the place(
(component) {
return component.date.isAfter(
DateTime.now().subtract(
const Period(days: 7),
),
);
},
).toList();
}
void _addTransaction(String txtitle, double txamount, DateTime chosenDate) {
closing newTransaction = Transaction(
title: txtitle,
quantity: txamount,
date: chosenDate,
id: DateTime.now().toString(),
);
setState(() {
_userTransactions.add(newTransaction);
});
}
void _startAddingNewTransaction(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (_) {
return GestureDetector(
onTap: (() {}),
little one: NewTransaction(
addTransaction: _addTransaction,
),
conduct: HitTestBehavior.opaque,
);
},
);
}
void _deleteTransaction(String id) {
setState(() {
_userTransactions.removeWhere((component) => component.id == id);
});
}
@override
Widget construct(BuildContext context) {
// ignore: unrelated_type_equality_checks
closing isLandscape = MediaQuery.of(context).orientation == Orientation;
closing varAppbar = AppBar(
title: const Textual content(
'Bills App',
type: TextStyle(fontFamily: 'OpenSans'),
),
actions: [
IconButton(
onPressed: () => _startAddingNewTransaction(context),
icon: const Icon(
Icons.add,
),
)
],
);
closing transactionListWidget = SizedBox(
top: (MediaQuery.of(context).dimension.top - varAppbar.preferredSize.top - MediaQuery.of(context).padding.high) * 0.75,
little one: TransactionList(
transactions: _userTransactions,
deleteTransaction: _deleteTransaction,
),
);
return Scaffold(
backgroundColor: Theme.of(context).primaryColorLight,
appBar: varAppbar,
physique: SingleChildScrollView(
little one: Column(
kids: [
if (isLandscape)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Show Chart'),
Switch(
value: _showChart,
onChanged: (value) {
setState(() {
_showChart = value;
});
},
),
],
),
if (!isLandscape)
SizedBox(
top: (MediaQuery.of(context).dimension.top - varAppbar.preferredSize.top - MediaQuery.of(context).padding.high) * 0.25,
little one: Chart(recentTransactions: _recentTransactions),
),
if (!isLandscape) transactionListWidget,
if (isLandscape)
_showChart
? SizedBox(
top: (MediaQuery.of(context).dimension.top - varAppbar.preferredSize.top - MediaQuery.of(context).padding.high) * 1,
little one: Chart(recentTransactions: _recentTransactions),
)
: transactionListWidget,
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton(
onPressed: () => _startAddingNewTransaction(context),
little one: const Icon(Icons.add),
),
);
}
}
[ad_2]
