proj reorg into folders;
fixed provider implementation; added TxnType radio picker
This commit is contained in:
19
lib/screens/about.dart
Normal file
19
lib/screens/about.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AboutScreen extends StatelessWidget {
|
||||
// change to AboutDialog
|
||||
const AboutScreen(
|
||||
{super.key}); //https://api.flutter.dev/flutter/material/AboutDialog-class.html
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('About Page'),
|
||||
backgroundColor: const Color.fromARGB(255, 185, 47, 5),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text('About Page Text, Lorum Ipsum and whatnot.'),
|
||||
));
|
||||
}
|
||||
}
|
||||
155
lib/screens/car_detail.dart
Normal file
155
lib/screens/car_detail.dart
Normal file
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:path/path.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:dash/utils/garage_model.dart';
|
||||
// import 'package:dash/main.dart';
|
||||
import 'package:dash/models/car.dart';
|
||||
import 'package:dash/screens/screens.dart';
|
||||
|
||||
class CarDetailScreen extends StatefulWidget {
|
||||
const CarDetailScreen({super.key, required this.carIndex});
|
||||
final int carIndex;
|
||||
|
||||
@override
|
||||
State<CarDetailScreen> createState() => _CarDetailScreenState();
|
||||
}
|
||||
|
||||
class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
//investigate
|
||||
// late Car car = context.watch<GarageModel>()._cars[widget.carIndex];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// late Car car = Provider.of<GarageModel>(context).cars[widget.carIndex];
|
||||
// late Car car = context.watch<GarageModel>()_cars[widget.carIndex];
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: const Color.fromARGB(255, 185, 47, 5),
|
||||
// title: Text(car.nickname ?? ""),
|
||||
title: const Text("View Car"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
const Text("plh img picker"),
|
||||
Center(
|
||||
// edit car screen
|
||||
child: Ink(
|
||||
decoration: const ShapeDecoration(
|
||||
color: Colors.lightBlue, shape: CircleBorder()),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
color: Colors.white,
|
||||
onPressed: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
EditCarScreen(carIndex: widget.carIndex)),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
iconSize: 48.0,
|
||||
icon: const Icon(Icons.directions_car),
|
||||
onPressed: (() => VoidCallback),
|
||||
),
|
||||
Consumer<GarageModel>(
|
||||
builder: (context, garage, child) => Column(
|
||||
children: [
|
||||
Text("Nickname: ${garage.cars[widget.carIndex].nickname}"),
|
||||
Text("VIN: ${garage.cars[widget.carIndex].vin}"),
|
||||
Text("License Plate: ${garage.cars[widget.carIndex].plate}"),
|
||||
Text(
|
||||
"Mileage: ${garage.cars[widget.carIndex].mileage.toString()}"),
|
||||
],
|
||||
),
|
||||
),
|
||||
CarTxns(carIndex: widget.carIndex),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => NewTxnScreen(carIndex: widget.carIndex),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CarTxns extends StatefulWidget {
|
||||
const CarTxns({super.key, required this.carIndex});
|
||||
final int carIndex;
|
||||
|
||||
@override
|
||||
State<CarTxns> createState() => _CurrentCar();
|
||||
}
|
||||
|
||||
class _CurrentCar extends State<CarTxns> {
|
||||
late Future _txns;
|
||||
late Car car;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
car =
|
||||
Provider.of<GarageModel>(context, listen: false).cars[widget.carIndex];
|
||||
_txns = Provider.of<GarageModel>(context, listen: false).getTxns(car.id!);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// car =
|
||||
// Provider.of<GarageModel>(context, listen: false).cars[widget.carIndex];
|
||||
// _txns = Provider.of<GarageModel>(context, listen: false).getTxns(car.id!);
|
||||
return FutureBuilder(
|
||||
future: _txns,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else {
|
||||
if (snapshot.error != null) {
|
||||
return const Center(
|
||||
child: Text('An error occurred'),
|
||||
);
|
||||
} else {
|
||||
return Expanded(child: Consumer<GarageModel>(
|
||||
builder: (context, garage, child) {
|
||||
return ListView.separated(
|
||||
// padding: const EdgeInsets.all(8),
|
||||
itemCount: garage.txns.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
// dense: true, //only affects text, use visualDensity instead
|
||||
visualDensity:
|
||||
const VisualDensity(horizontal: 0, vertical: -4),
|
||||
leading: const Icon(Icons.local_gas_station),
|
||||
title: Text(garage.txns[index].txntype ?? "type"),
|
||||
subtitle: Text(garage.txns[index].note ?? "note"),
|
||||
onTap: (() => VoidCallback)),
|
||||
separatorBuilder: (BuildContext context, int index) =>
|
||||
const Divider(),
|
||||
);
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
156
lib/screens/car_edit.dart
Normal file
156
lib/screens/car_edit.dart
Normal file
@@ -0,0 +1,156 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:dash/utils/garage_model.dart';
|
||||
import 'package:dash/models/car.dart';
|
||||
|
||||
class EditCarScreen extends StatefulWidget {
|
||||
const EditCarScreen({super.key, required this.carIndex});
|
||||
final int carIndex;
|
||||
|
||||
@override
|
||||
State<EditCarScreen> createState() => _EditCarScreenState();
|
||||
}
|
||||
|
||||
class _EditCarScreenState extends State<EditCarScreen> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
late GarageModel garage;
|
||||
late Car car;
|
||||
late int carIndex = widget.carIndex;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// garage = Provider.of<GarageModel>(context);
|
||||
// car = garage.cars[carIndex];
|
||||
// car = Provider.of<GarageModel>(context).cars[carIndex];
|
||||
// may need to add garage here, too
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// var garage = context.read<GarageModel>();
|
||||
garage = Provider.of<GarageModel>(context);
|
||||
car = garage.cars[carIndex];
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Edit ${car.nickname}"),
|
||||
backgroundColor: const Color.fromARGB(255, 185, 47, 5),
|
||||
),
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
TextFormField(
|
||||
initialValue: car.nickname,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nickname',
|
||||
),
|
||||
onSaved: (val) => setState(() => car.nickname = val),
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter a nickname';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
initialValue: car.vin,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'VIN',
|
||||
),
|
||||
onSaved: (val) => setState(() => car.vin = val),
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter a unique VIN';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
initialValue: car.plate,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'License Plate',
|
||||
),
|
||||
onSaved: (val) => setState(() => car.plate = val),
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter a license plate';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
initialValue: car.mileage.toString(),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Mileage',
|
||||
),
|
||||
onSaved: (val) =>
|
||||
setState(() => car.mileage = int.parse(val ?? "")),
|
||||
// inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly] //try this?
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter car\'s current mileage';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
final updateForm = _formKey.currentState!;
|
||||
if (updateForm.validate()) {
|
||||
//validate form
|
||||
updateForm
|
||||
.save(); //save values (reqd before putting them anywhere)
|
||||
garage.update(car, carIndex);
|
||||
updateForm.reset();
|
||||
Navigator.pop(context);
|
||||
// Navigator.pushNamed(context, '/');
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: const <Widget>[
|
||||
//expand these children, too tight
|
||||
Icon(Icons.save),
|
||||
Text('Save Changes'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: ElevatedButton(
|
||||
onPressed: (() => VoidCallback),
|
||||
onLongPress: () {
|
||||
garage.delete(car);
|
||||
Navigator.pop(context);
|
||||
// Navigator.pushNamed(context, '/');
|
||||
},
|
||||
child: Row(children: const <Widget>[
|
||||
Icon(Icons.delete),
|
||||
Text('Delete'),
|
||||
]),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: ElevatedButton(
|
||||
onPressed: (() => VoidCallback),
|
||||
child: Row(children: const <Widget>[
|
||||
Icon(Icons.sync_alt),
|
||||
Text('enable/disable'),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
166
lib/screens/car_new.dart
Normal file
166
lib/screens/car_new.dart
Normal file
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:dash/utils/garage_model.dart';
|
||||
import 'package:dash/models/car.dart';
|
||||
import '../utils/garage_model.dart';
|
||||
|
||||
class NewCarScreen extends StatefulWidget {
|
||||
const NewCarScreen({super.key});
|
||||
|
||||
@override
|
||||
State<NewCarScreen> createState() => _NewCarScreenState();
|
||||
}
|
||||
|
||||
class _NewCarScreenState extends State<NewCarScreen> {
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
Car car = Car(); //initialization is required
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Add New Car'),
|
||||
backgroundColor: const Color.fromARGB(255, 185, 47, 5),
|
||||
),
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
//new car form text fields
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nickname',
|
||||
),
|
||||
onSaved: (val) => setState(() => car.nickname = val),
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter a nickname';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'VIN',
|
||||
),
|
||||
onSaved: (val) => setState(() => car.vin = val),
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter a unique VIN';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'License Plate',
|
||||
),
|
||||
onSaved: (val) => setState(() => car.plate = val),
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter a license plate';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Mileage',
|
||||
),
|
||||
onSaved: (val) =>
|
||||
setState(() => car.mileage = int.parse(val ?? "")),
|
||||
// inputFormatters: <TextInputFormatter>[FilteringTextInputFormatter.digitsOnly] //try this?
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter car\'s current mileage';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: ElevatedButton(
|
||||
// onPressed: () => _onSubmit(context),
|
||||
onPressed: () {
|
||||
final form = formKey.currentState!;
|
||||
if (form.validate()) {
|
||||
//validate form
|
||||
form.save(); //save values (reqd before putting them anywhere)
|
||||
setState(() {
|
||||
//modify state of car (necessary?)
|
||||
car = Car(
|
||||
vin: car.vin,
|
||||
nickname: car.nickname,
|
||||
plate: car.plate,
|
||||
mileage: car.mileage);
|
||||
});
|
||||
// var garage = context.read<GarageModel>();
|
||||
// garage.add(car);
|
||||
Provider.of<GarageModel>(context, listen: false).add(car);
|
||||
form.reset();
|
||||
// Navigator.pop(context);
|
||||
Navigator.pushNamed(context, '/');
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: const <Widget>[
|
||||
Icon(Icons.add),
|
||||
Text('Add Car'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_onSubmit(context) async {
|
||||
final form = formKey.currentState!;
|
||||
if (form.validate()) {
|
||||
//validate form
|
||||
form.save(); //save values (reqd before putting them anywhere)
|
||||
setState(() {
|
||||
//modify state of car (necessary?)
|
||||
car = Car(
|
||||
vin: car.vin,
|
||||
nickname: car.nickname,
|
||||
plate: car.plate,
|
||||
mileage: car.mileage);
|
||||
});
|
||||
var garage = context.read<GarageModel>(); //implement Provider
|
||||
garage.add(car);
|
||||
form.reset();
|
||||
Navigator.pushNamed(context, '/');
|
||||
}
|
||||
}
|
||||
|
||||
void submit(BuildContext context) async {
|
||||
var garage = context.read<GarageModel>();
|
||||
|
||||
final form = formKey.currentState!;
|
||||
if (form.validate()) {
|
||||
//validate form
|
||||
form.save(); //save values (reqd before putting them anywhere)
|
||||
setState(() {
|
||||
//modify state of car (necessary?)
|
||||
car = Car(
|
||||
vin: car.vin,
|
||||
nickname: car.nickname,
|
||||
plate: car.plate,
|
||||
mileage: car.mileage);
|
||||
});
|
||||
garage.add(car);
|
||||
// Provider.of<GarageModel>(context).add(car);
|
||||
form.reset();
|
||||
Navigator.pop(context);
|
||||
// Navigator.pushNamed(context, '/');
|
||||
}
|
||||
}
|
||||
}
|
||||
6
lib/screens/screens.dart
Normal file
6
lib/screens/screens.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
export 'package:dash/screens/about.dart';
|
||||
export 'package:dash/screens/car_new.dart';
|
||||
export 'package:dash/screens/car_detail.dart';
|
||||
export 'package:dash/screens/car_edit.dart';
|
||||
export 'package:dash/screens/txn_new.dart';
|
||||
export 'package:dash/screens/txn_type.dart';
|
||||
149
lib/screens/txn_new.dart
Normal file
149
lib/screens/txn_new.dart
Normal file
@@ -0,0 +1,149 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:dash/utils/garage_model.dart';
|
||||
import 'package:dash/models/car.dart';
|
||||
import 'package:dash/models/txn.dart';
|
||||
import 'package:dash/screens/txn_type.dart';
|
||||
|
||||
class NewTxnScreen extends StatefulWidget {
|
||||
const NewTxnScreen({super.key, required this.carIndex});
|
||||
final int carIndex;
|
||||
|
||||
@override
|
||||
State<NewTxnScreen> createState() => _NewTxnScreenState();
|
||||
}
|
||||
|
||||
class _NewTxnScreenState extends State<NewTxnScreen> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
late Car car;
|
||||
late int carIndex = widget.carIndex;
|
||||
// late var garage;
|
||||
DateTime datetime = DateTime.now();
|
||||
Txn txn = Txn();
|
||||
late TxnType txnType = TxnType();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
car = Provider.of<GarageModel>(context, listen: false).cars[carIndex];
|
||||
// garage = Provider.of<GarageModel>(context, listen: false);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<void> _selectDate(BuildContext context) async {
|
||||
final DateTime? timepicked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: datetime,
|
||||
firstDate: DateTime.utc(1776, 7, 4),
|
||||
lastDate: DateTime.utc(2222, 2, 22));
|
||||
if (timepicked != null && timepicked != datetime) {
|
||||
setState(() => datetime = timepicked);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// txnType = TxnType();
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Add new txn for ${car.nickname}"),
|
||||
backgroundColor: const Color.fromARGB(255, 185, 47, 5),
|
||||
),
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
txnType,
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: IconButton(
|
||||
onPressed: () => _selectDate(context),
|
||||
icon: const Icon(Icons.calendar_month)),
|
||||
),
|
||||
Flexible(
|
||||
flex: 3,
|
||||
child: InputDatePickerFormField(
|
||||
firstDate: DateTime.utc(1776, 7, 4),
|
||||
lastDate: DateTime.utc(2222, 2, 22),
|
||||
initialDate: datetime,
|
||||
onDateSaved: (val) => setState(
|
||||
() => txn.datetime = val.millisecondsSinceEpoch)),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Cost',
|
||||
),
|
||||
initialValue: "0",
|
||||
onSaved: (val) =>
|
||||
setState(() => txn.cost = double.parse(val ?? "0")),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
TextFormField(
|
||||
initialValue: car.mileage.toString(),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Mileage',
|
||||
),
|
||||
onSaved: (val) =>
|
||||
setState(() => txn.mileage = int.parse(val ?? "")),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Must be >= current mileage";
|
||||
} else if (int.parse(value) < car.mileage!.toInt()) {
|
||||
return 'Must be >= current mileage';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Note',
|
||||
),
|
||||
onSaved: (val) => setState(() => txn.note = val),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
final form = _formKey.currentState!;
|
||||
if (form.validate()) {
|
||||
form.save();
|
||||
setState(() {
|
||||
txn.datetime = DateTime.now().millisecondsSinceEpoch;
|
||||
txn.txntype = txnType.selectedText;
|
||||
print(
|
||||
"txntype set to ${txn.txntype} from radio ${txnType.selectedText}");
|
||||
txn.carid = car.id;
|
||||
car.mileage = txn.mileage; // update car mileage too
|
||||
});
|
||||
print(txn.toMap());
|
||||
Provider.of<GarageModel>(context, listen: false)
|
||||
.update(car, carIndex);
|
||||
Provider.of<GarageModel>(context, listen: false)
|
||||
.insertTxn(txn);
|
||||
form.reset();
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: const <Widget>[
|
||||
//expand these children, too tight
|
||||
Icon(Icons.save),
|
||||
Text('Save Changes'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
63
lib/screens/txn_type.dart
Normal file
63
lib/screens/txn_type.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TxnType extends StatefulWidget {
|
||||
TxnType({super.key});
|
||||
late String selectedText;
|
||||
|
||||
@override
|
||||
TxnTypeState createState() => TxnTypeState();
|
||||
}
|
||||
|
||||
class TxnTypeState extends State<TxnType> {
|
||||
int selectedIndex = 0;
|
||||
|
||||
// should I do this? or set manually in the declaration
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
selectedIndex = 0;
|
||||
widget.selectedText = "Gas";
|
||||
}
|
||||
|
||||
// how to cough up value?
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
|
||||
rIcon(index: 0, text: "Gas", icon: Icons.local_gas_station),
|
||||
rIcon(index: 1, text: "Oil", icon: Icons.water_drop),
|
||||
rIcon(index: 2, text: "Other", icon: Icons.build),
|
||||
// rIcon(index: 3, text: "Renewal", icon: Icons.calendar_view_day),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget rIcon(
|
||||
{required int index, required String text, required IconData icon}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: selectedIndex == index
|
||||
? const Color.fromARGB(255, 185, 47, 5)
|
||||
: null,
|
||||
),
|
||||
child: Ink(
|
||||
child: InkResponse(
|
||||
child: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: selectedIndex == index ? Colors.white : null,
|
||||
),
|
||||
Text(text,
|
||||
style: TextStyle(
|
||||
color:
|
||||
selectedIndex == index ? Colors.white : null))
|
||||
],
|
||||
),
|
||||
onTap: () => setState(() {
|
||||
selectedIndex = index;
|
||||
widget.selectedText = text;
|
||||
}))));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user