This commit is contained in:
Thomas Atkins 2021-04-10 14:01:03 -05:00
parent 9416b1188e
commit 2fc02c6272
2 changed files with 12 additions and 3 deletions

View File

@ -1,9 +1,14 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:loc_chain_app/widgets/navbar.dart'; import 'package:loc_chain_app/widgets/navbar.dart';
import 'dart:math';
void main() async { void main() async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
final id = prefs.getString('id') ?? '0';
if (id == '0') {
prefs.setString('id', Random().nextInt(10000).toString());
}
runApp(App()); runApp(App());
} }

View File

@ -5,8 +5,10 @@ import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:nearby_connections/nearby_connections.dart'; import 'package:nearby_connections/nearby_connections.dart';
import 'package:shared_preferences/shared_preferences.dart';
class BluetoothPage extends StatefulWidget { class BluetoothPage extends StatefulWidget {
BluetoothPage({Key key, this.title}) : super(key: key); BluetoothPage({Key? key, required this.title}) : super(key: key);
final String title; final String title;
@override @override
@ -14,7 +16,7 @@ class BluetoothPage extends StatefulWidget {
} }
class _BluetoothPageState extends State<BluetoothPage> { class _BluetoothPageState extends State<BluetoothPage> {
final String userName = Random().nextInt(10000).toString(); final id = SharedPreferences.getInstance().then((s) => s.getString('id'));
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -22,7 +24,9 @@ class _BluetoothPageState extends State<BluetoothPage> {
appBar: AppBar( appBar: AppBar(
title: Text(widget.title), title: Text(widget.title),
), ),
body: Center(), body: Center(
child: Text('$id'),
),
); );
} }
} }