I know there are a ton of questions like these but I'm brand new to Flutter and I haven't found a post that suits my needs or maybe I'm just thinking about it wrong.
When developing with Flutter you might have seen that almost every screen requires to pass data from one screen to another and might also need to receive data back from another screen.
home.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'applicationbar.dart';
import 'navigationdrawer.dart';
import 'bluetooth.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
String _string = '0m'; //so if _isFeetChecked is true in settings.dart this is '0ft'
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[900],
appBar: ApplicationBar(title: 'Luggage Follower'),
drawer: NavigationDrawer(),
body:Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 0),
child: Text('good Status', style: Theme.of(context).textTheme.body2),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 0),
child: Text('Paired', style: Theme.of(context).textTheme.body1),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 20,horizontal: 0),
child: Divider(height: 3.0, color: Colors.pinkAccent, indent: 150, endIndent: 150),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 0),
child: Text('Distance to Luggage', style: Theme.of(context).textTheme.body2),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 0),
child: Text(_string, style: Theme.of(context).textTheme.body1), //dynamic text here
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 0),
child: LuggageFollow(),
),
],
),
);
}
}
settings.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
import 'applicationbar.dart';
import 'navigationdrawer.dart';
class SettingsData {
bool feet;
bool metres;
SettingsData({this.feet, this.metres});
}
class Settings extends StatefulWidget {
@override
_SettingsState createState() => _SettingsState();
}
class _SettingsState extends State<Settings> {
static bool _isFeetChecked = false;
static bool _isMetersChecked = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: ApplicationBar(title: 'Settings'),
drawer: NavigationDrawer(),
body: Column(
//crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(vertical: 20.0,horizontal: 20),
child: Text('Distance Units')
),
Divider(
height: 3.0,
color: Colors.pink,
),
Padding(
padding: EdgeInsets.symmetric(vertical: 20.0,horizontal: 0),
child: CheckboxListTile(
title: Text('Distance in feet', style: Theme.of(context).textTheme.body1),
value: _isFeetChecked,
onChanged: (bool value) {
setState(() {
_isFeetChecked = value; _isMetersChecked = !value;});
},
checkColor: Colors.white,
activeColor: Colors.pink,
subtitle: Text('1 foot ~ 0.3 metres',style: Theme.of(context).textTheme.display2),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 20.0,horizontal: 0),
child: CheckboxListTile(
title: Text('Distance in metres', style: Theme.of(context).textTheme.body1),
value: _isMetersChecked,
onChanged: (bool value) {
setState(() { _isMetersChecked = value; _isFeetChecked = !value;updateData();});
},
checkColor: Colors.white,
activeColor: Colors.pink,
subtitle: Text('1 metre ~ 3 feet',style: Theme.of(context).textTheme.display2),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 30.0,horizontal: 20),
child: Text('Notifications')
),
Divider(
height: 3.0,
color: Colors.pink,
),
),
),
],
),
);
}
}