Skip to content

Commit

Permalink
Finished first version
Browse files Browse the repository at this point in the history
  • Loading branch information
xsadra committed May 28, 2021
1 parent b1f02ad commit 51a3526
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:auto_route/auto_route.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide Router;

import '../../../core/routes/router.gr.dart';

class BottomNavBar extends StatelessWidget {
const BottomNavBar({
Expand All @@ -22,7 +25,13 @@ class BottomNavBar extends StatelessWidget {
top: -14,
initialActiveIndex: 0,
//optional, default as 0
onTap: (int i) => print('click index=$i'),
onTap: (int pageIndex) {
if (pageIndex == 0) {
ExtendedNavigator.of(context).replace(Routes.HomePageRoute);
} else if (pageIndex == 1) {
ExtendedNavigator.of(context).pushInputTagPageRoute();
}
},
);
}
}
7 changes: 6 additions & 1 deletion lib/clash/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../core/constants/texts.dart';
import '../../../injection_container.dart' as injection;
import '../../presentation/bloc/player/bloc.dart';
import '../../presentation/bloc/upcomingchest/bloc.dart';
import '../widgets/bottom_navigation_bar.dart';
import '../bloc/currentplayertag/bloc.dart';
import 'bottom_navigation_bar.dart';
import 'player_nested_tab_page.dart';

class HomePage extends StatelessWidget {
Expand All @@ -15,8 +18,10 @@ class HomePage extends StatelessWidget {
Widget build(BuildContext context) {
var playerProviders = [
BlocProvider(create: (context) => injection.sl<PlayerBloc>()),
BlocProvider(create: (context) => injection.sl<CurrentPlayerTagBloc>()),
BlocProvider(create: (context) => injection.sl<UpcomingChestsBloc>())
];
log('build', name: 'HomePage');
return Scaffold(
appBar: AppBar(
title: Text(APP_TITLE),
Expand Down
89 changes: 54 additions & 35 deletions lib/clash/presentation/pages/player_nested_tab_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:developer';

import 'package:flutter/material.dart' hide Card;
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../presentation/bloc/player/bloc.dart';
import '../../presentation/bloc/upcomingchest/bloc.dart';
import '../bloc/currentplayertag/bloc.dart';
import '../bloc/player/bloc.dart' hide Loaded;
import '../bloc/upcomingchest/bloc.dart' hide Loaded;
import '../widgets/widgets.dart';

class PlayerNestedTabPage extends StatefulWidget {
Expand All @@ -16,29 +19,53 @@ class _PlayerNestedTabPageState extends State<PlayerNestedTabPage>

@override
Widget build(BuildContext context) {
log('build', name: 'PlayerNestedTabPage');

double screenHeight = MediaQuery.of(context).size.height;
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
TabBar(
controller: _nestedTabController,
indicatorColor: Colors.teal,
labelColor: Colors.teal,
unselectedLabelColor: Colors.black54,
isScrollable: true,
tabs: _playerTabBarList(),
),
Expanded(
//flex: 1,
child: Container(
height: screenHeight * 0.72,
child: TabBarView(
controller: _nestedTabController,
children: _playerTabBarViewList(),
),
return BlocListener<CurrentPlayerTagBloc, CurrentPlayerTagState>(
listener: (BuildContext context, state) {
log('BlocListener', name: 'PlayerNestedTabPage BlocListener');
log(state.runtimeType.toString(),
name: 'PlayerNestedTabPage BlocListener');

if (state is Loaded) {
log('state is Loaded', name: 'PlayerNestedTabPage BlocListener');
var playerTag = state.playerTag.playerTag;

log('add GetPlayerEvent to PlayerBloc: ' + playerTag,
name: 'PlayerNestedTabPage BlocListener');

context.read<PlayerBloc>().add(GetPlayerEvent(playerTag));
log('add GetUpcomingChestsEvent to UpcomingChestsBloc: ' + playerTag,
name: 'PlayerNestedTabPage BlocListener');
context
.read<UpcomingChestsBloc>()
.add(GetUpcomingChestsEvent(playerTag));
}
},
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
TabBar(
controller: _nestedTabController,
indicatorColor: Colors.teal,
labelColor: Colors.teal,
unselectedLabelColor: Colors.black54,
isScrollable: true,
tabs: _playerTabBarList(),
),
)
],
Expanded(
//flex: 1,
child: Container(
height: screenHeight * 0.72,
child: TabBarView(
controller: _nestedTabController,
children: _playerTabBarViewList(),
),
),
)
],
),
);
}

Expand All @@ -56,9 +83,6 @@ class _PlayerNestedTabPageState extends State<PlayerNestedTabPage>
Tab(
text: "Achieved",
),
Tab(
text: "Set Player",
),
];
}

Expand All @@ -76,21 +100,16 @@ class _PlayerNestedTabPageState extends State<PlayerNestedTabPage>
Container(
child: AchievementsView(),
),
Container(
child: SetCurrentPlayerView(),
),
];
}

@override
void initState() {
log('initState', name: 'PlayerNestedTabPage');
super.initState();
_nestedTabController = new TabController(length: 5, vsync: this);
// context.read<PlayerBloc>().
context.read<PlayerBloc>().add(GetPlayerEvent('%23PPGRVJJQ'));
context
.read<UpcomingChestsBloc>()
.add(GetUpcomingChestsEvent('%23PPGRVJJQ'));
_nestedTabController =
new TabController(length: _playerTabBarList().length, vsync: this);
context.read<CurrentPlayerTagBloc>().add(GetCurrentPlayerTagEvent());
}

@override
Expand Down
86 changes: 57 additions & 29 deletions lib/clash/presentation/widgets/input_tag.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import 'package:clash_royale_assistant/clash/presentation/bloc/player/bloc.dart';
import 'package:flutter/material.dart';
import 'dart:developer';

import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart' hide Router;
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../core/routes/router.gr.dart';
import '../../data/datasources/validate_tag_remote_data_source.dart';
import '../../domain/entities/current_player_tag.dart';
import '../bloc/currentplayertag/bloc.dart';
import '../bloc/validatetag/bloc.dart';

class InputTag extends StatefulWidget {
const InputTag({Key key}) : super(key: key);

Expand All @@ -12,8 +20,7 @@ class InputTag extends StatefulWidget {

class _InputTagState extends State<InputTag> {
final controller = TextEditingController();
String inputString =
'PPGRVJJQ'; // Remove Step: remove it after Fix 'read user tag' and replace it
String inputString = '';

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -66,25 +73,43 @@ class _InputTagState extends State<InputTag> {
);
}

TextField _inputTextField() {
return TextField(
onChanged: (value) => inputString = value,
onSubmitted: (_) => addPlayerTag(),
controller: controller,
keyboardType: TextInputType.text,
inputFormatters: [UpperCaseTextFormatter()],
maxLength: 10,
maxLines: 1,
style: TextStyle(fontWeight: FontWeight.bold, color: Color(0xFF00893F)),
decoration: InputDecoration(
fillColor: Colors.blueGrey,
labelText: 'Enter your Player Tag',
labelStyle:
TextStyle(fontWeight: FontWeight.bold, color: Colors.black54),
prefixIcon: Icon(Icons.tag, color: Colors.green),
border: OutlineInputBorder(),
hintText: 'XXXXXXXXX',
hintStyle: TextStyle(color: Colors.teal)),
Widget _inputTextField() {
bool showError = false;
return BlocBuilder<ValidateTagBloc, ValidateTagState>(
builder: (BuildContext context, state) {
log(state.runtimeType.toString(),
name: ' InputTag > _inputTextField()');
if (state is IsValid) {
context.read<CurrentPlayerTagBloc>().add(SaveCurrentPlayerTagEvent(
playerTag: CurrentPlayerTag(playerTag: inputString)));
log('Navigate to HomePage', name: 'InputTag > _inputTextField()');
ExtendedNavigator.of(context).replace(Routes.HomePageRoute);
} else if (state is NotValid) {
showError = true;
}
return TextField(
onChanged: (value) => inputString = value,
onSubmitted: (_) => _validateTag(),
controller: controller,
keyboardType: TextInputType.text,
inputFormatters: [UpperCaseTextFormatter()],
maxLength: 10,
maxLines: 1,
style:
TextStyle(fontWeight: FontWeight.bold, color: Color(0xFF00893F)),
decoration: InputDecoration(
errorText: showError ? 'Wrong tag, try again!' : null,
fillColor: Colors.blueGrey,
labelText: 'Enter your Player Tag',
labelStyle:
TextStyle(fontWeight: FontWeight.bold, color: Colors.black54),
prefixIcon: Icon(Icons.tag, color: Colors.green),
border: OutlineInputBorder(),
hintText: 'XXXXXXXXX',
hintStyle: TextStyle(color: Colors.teal)),
);
},
//listenWhen: (previous, current) => current != previous,
);
}

Expand All @@ -93,21 +118,25 @@ class _InputTagState extends State<InputTag> {
children: [
Expanded(
child: ElevatedButton(
onPressed: addPlayerTag,
onPressed: _validateTag,
child: Text('Search'),
),
),
],
);
}

void addPlayerTag() {
void _validateTag() {
controller.clear();
inputString = '%23' + inputString.replaceAll('#', '');

context.read<PlayerBloc>().add(GetPlayerEvent(inputString));
// context.read<CurrentPlayerTagBloc>().add(
// SaveCurrentPlayerTagEvent(CurrentPlayerTag(playerTag: inputString)));
log(inputString, name: 'InputTag > _validateTag()');

context
.read<ValidateTagBloc>()
.add(CheckValidateTagEvent(tag: inputString, type: RoyaleTags.player));
log('add CheckValidateTagEvent event to ValidateTagBloc',
name: 'InputTag > _validateTag()');
}
}

Expand Down Expand Up @@ -149,7 +178,6 @@ class SetPlayerHelpText extends StatelessWidget {
child: Text(
rowText,
style: TextStyle(fontSize: 16),
//softWrap: true,
),
),
],
Expand Down
27 changes: 20 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart' hide Router;
import 'package:flutter_bloc/flutter_bloc.dart';

import 'clash/presentation/pages/home_page.dart';
import 'clash/presentation/bloc/currentplayertag/bloc.dart';
import 'core/constants/texts.dart';
import 'core/routes/router.gr.dart';
import 'injection_container.dart' as injection;

void main() async {
Expand All @@ -13,12 +16,22 @@ void main() async {
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: APP_TITLE,
theme: ThemeData().copyWith(
primaryColor: Color(0xFF190F2A),
return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => injection.sl<CurrentPlayerTagBloc>()
..add(GetCurrentPlayerTagEvent())),
],
child: MaterialApp(
title: APP_TITLE,

builder: ExtendedNavigator(router: Router()),
debugShowCheckedModeBanner: false,
theme: ThemeData().copyWith(
primaryColor: Color(0xFF190F2A),
),
//home: HomePage(),
),
home: HomePage(),
);
}
}

0 comments on commit 51a3526

Please sign in to comment.