live_game_lib 0.0.4 live_game_lib: ^0.0.4 copied to clipboard
A Game Libary for creating live multiplayergames with flutter and firebase very fast and easy.
Live Game Library #
A Flutter Library for creating Games fast
Getting Started #
- Setup your Firebase project and add it to project
- Setup you real time database real time database
- Import this library and create your list of games
import 'package:example/games/guess_the_word.dart';
import 'package:live_game_lib/backend/game_prefab.dart';
Map<String, Game> games = {
"my first game": Game(
"my first game",
myFirstGameScreen,
usesLobby: true,
canPostjoin: true,
),
};
- Create your First Game Call Function in another File
import 'package:flutter/material.dart';
import 'package:live_game_lib/backend/room.dart';
Widget myFirstGameScreen(BuildContext context, Room r) {
String textDatabase = r.getString("syncedString") ?? "";
return return Scaffold(
appBar: AppBar(
title: const Text("Synced Text Field"),
),
body: Center (
TextFormField(
initialValue: textDatabase,
onChanged: (text) {
r.set("syncedString", text);
},
)
)
)
}
- Create Your Game Manager in your main file
import 'package:example/firebase_options.dart';
import 'package:example/gamelist.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:live_game_lib/backend/gamemanager.dart';
GameManager? inst;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
inst = GameManager(games: games);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Live Games Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
initialRoute: '/',
routes: inst?.routes
);
}
}
- For more examples, see the example project in the example folder