Return to Provider and remove GetIt
This commit is contained in:
parent
4df6383652
commit
eec5994c30
6 changed files with 50 additions and 35 deletions
|
|
@ -1,11 +1,9 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:frosty/screens/home.dart';
|
||||
import 'package:frosty/stores/auth_store.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
void main() {
|
||||
GetIt.I.registerSingleton<AuthStore>(AuthStore());
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
|
|
@ -14,23 +12,31 @@ class MyApp extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final auth = GetIt.I<AuthStore>();
|
||||
return MaterialApp(
|
||||
title: 'Frosty',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
home: Scaffold(
|
||||
body: FutureBuilder(
|
||||
future: auth.init(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return const Home();
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
Provider<AuthStore>(create: (_) => AuthStore()),
|
||||
],
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
return MaterialApp(
|
||||
title: 'Frosty',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
home: Scaffold(
|
||||
body: FutureBuilder(
|
||||
future: context.read<AuthStore>().init(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return const Home();
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:frosty/stores/auth_store.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class Settings extends StatelessWidget {
|
||||
const Settings({Key? key}) : super(key: key);
|
||||
|
|
@ -9,7 +9,7 @@ class Settings extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
debugPrint('settings');
|
||||
final auth = GetIt.I<AuthStore>();
|
||||
final auth = context.read<AuthStore>();
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Settings'),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:frosty/models/channel.dart';
|
||||
import 'package:frosty/stores/auth_store.dart';
|
||||
import 'package:frosty/widgets/chat.dart';
|
||||
import 'package:frosty/widgets/video.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class VideoChat extends StatelessWidget {
|
||||
final Channel channelInfo;
|
||||
|
|
@ -20,7 +22,7 @@ class VideoChat extends StatelessWidget {
|
|||
child: Video(channelName: channelInfo.userLogin),
|
||||
),
|
||||
Expanded(
|
||||
child: Chat(channelInfo: channelInfo),
|
||||
child: Chat(auth: context.read<AuthStore>(), channelInfo: channelInfo),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@ import 'package:flutter_mobx/flutter_mobx.dart';
|
|||
import 'package:frosty/models/channel.dart';
|
||||
import 'package:frosty/stores/auth_store.dart';
|
||||
import 'package:frosty/stores/chat_store.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
class Chat extends StatefulWidget {
|
||||
final AuthStore auth;
|
||||
final Channel channelInfo;
|
||||
|
||||
const Chat({Key? key, required this.channelInfo}) : super(key: key);
|
||||
const Chat({Key? key, required this.auth, required this.channelInfo}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ChatState createState() => _ChatState();
|
||||
}
|
||||
|
||||
class _ChatState extends State<Chat> {
|
||||
late final ChatStore chatStore = ChatStore(auth: GetIt.I<AuthStore>(), channelInfo: widget.channelInfo);
|
||||
late final ChatStore chatStore = ChatStore(auth: widget.auth, channelInfo: widget.channelInfo);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
|||
23
pubspec.lock
23
pubspec.lock
|
|
@ -317,13 +317,6 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
get_it:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: get_it
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "7.2.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -344,7 +337,7 @@ packages:
|
|||
name: http
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.3"
|
||||
version: "0.13.4"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -443,6 +436,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
octo_image:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -534,6 +534,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.2.3"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.0.1"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ dependencies:
|
|||
intl: ^0.17.0
|
||||
cached_network_image: ^3.1.0
|
||||
webview_flutter: ^2.0.13
|
||||
provider: ^6.0.1
|
||||
mobx: ^2.0.0
|
||||
flutter_mobx: ^2.0.0
|
||||
get_it: ^7.2.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue