Compare commits

...

3 Commits

Author SHA1 Message Date
51b0cbe89b Added TODO 2024-05-12 14:43:51 +03:00
9f720bdf75 Fix providers 2024-05-12 14:43:16 +03:00
2c2221f7f1 "Steal" theme from example app 2024-05-12 13:53:29 +03:00
2 changed files with 93 additions and 38 deletions

View File

@@ -1,7 +1,7 @@
import 'dart:math'; import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gymlink_module_web/main_mobile.dart'; import 'package:gymlink_module_web/pages/main.dart';
import 'package:gymlink_module_web/providers/main.dart'; import 'package:gymlink_module_web/providers/main.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@@ -17,12 +17,8 @@ class MyExampleApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
title: 'GymLink Example App', title: 'GymLink Example App',
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
home: ChangeNotifierProvider( home: const ExampleMainPage(),
create: (_) => GymLinkProvider(), theme: ThemeData.dark(useMaterial3: true),
child: Consumer<GymLinkProvider>(
builder: (context, provider, __) => const ExamplePage(),
),
),
); );
} }
} }
@@ -34,42 +30,101 @@ class ExamplePage extends StatefulWidget {
State<ExamplePage> createState() => _ExamplePageState(); State<ExamplePage> createState() => _ExamplePageState();
} }
Widget getDrawer(BuildContext context) => Drawer(
child: Column(
children: [
const DrawerHeader(child: Text('Drawer Header')),
ListTile(
leading: const Icon(Icons.home),
title: const Text('Home'),
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ExampleMainPage(),
),
),
),
ListTile(
leading: const Icon(Icons.search),
title: const Text('Example page'),
onTap: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const ExampleSecondPage(),
)),
),
],
),
);
class ExampleMainPage extends StatelessWidget {
const ExampleMainPage({super.key});
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => GymLinkProvider(),
child: Consumer<GymLinkProvider>(
builder: (_, value, __) => const ExamplePage(),
));
}
}
class _ExamplePageState extends State<ExamplePage> { class _ExamplePageState extends State<ExamplePage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
context.read<GymLinkProvider>().onTokenReceived('token123'); Future.microtask(
() => context.read<GymLinkProvider>().onTokenReceived('token123'));
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Consumer<GymLinkProvider>( return Scaffold(
builder: (context, provider, __) => Scaffold( appBar: AppBar(
appBar: AppBar(title: const Text('GymLink Example App')), title: const Text('GymLink Example App'),
body: Column( ),
children: [ drawer: getDrawer(context),
const Text('test'), body: Column(
IconButton( children: [
icon: const Icon(Icons.abc), const Text('test'),
onPressed: () { IconButton(
provider.onTokenReceived('token123'); icon: const Icon(Icons.abc),
}, onPressed: () {
), context.read<GymLinkProvider>().onTokenReceived('token123');
const Expanded( },
child: MyApp(), ),
), Expanded(
const SizedBox( child:
height: 20, MainPage(isLoading: context.watch<GymLinkProvider>().isLoading),
), ),
const Text('Bottom text') const SizedBox(
], height: 20,
), ),
floatingActionButton: IconButton( const Text('Bottom text')
icon: const Icon(Icons.search), ],
onPressed: () { ),
provider.changeTheme(Random().nextInt(0xffffff + 1)); floatingActionButton: IconButton(
}, icon: const Icon(Icons.search),
), onPressed: () {
context
.read<GymLinkProvider>()
.changeTheme(Random().nextInt(0xffffff + 1));
},
),
);
}
}
class ExampleSecondPage extends StatelessWidget {
const ExampleSecondPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('GymLink Example App'),
),
drawer: getDrawer(context),
body: const Center(
child: Text('Example page'),
), ),
); );
} }

View File

@@ -171,8 +171,8 @@ class _MainPageState extends State<MainPage> {
Expanded( Expanded(
child: GridView.builder( child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount: (MediaQuery.sizeOf(context).width ~/ 150)
(MediaQuery.sizeOf(context).width ~/ 250).floor(), .floor(), //TODO: Make it adaptive size
), ),
itemCount: testData.length, itemCount: testData.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
@@ -180,7 +180,7 @@ class _MainPageState extends State<MainPage> {
return ProductCard( return ProductCard(
imagePath: Image( imagePath: Image(
image: AssetImage('assets/${product['image']!}'), image: AssetImage('assets/${product['image']!}'),
width: 100, width: 50,
), ),
name: product['name']!, name: product['name']!,
price: product['price']!, price: product['price']!,